Hi all. I just finished this piece of code and wanted some thoughts on it. Like if there are ways to do this more effectively than how I have it.
The whole idea is that if this app is used on a computer without ACE then determine if Jet is installed. Let me know what you think. I have searched these forums and google for ways of doing this but not much luck.
The whole idea is that if this app is used on a computer without ACE then determine if Jet is installed. Let me know what you think. I have searched these forums and google for ways of doing this but not much luck.
VB.NET:
'determine if ACE or Jet data provider is installed
Dim aceExists As String = My.Computer.FileSystem.SpecialDirectories.ProgramFiles & _
"\Common Files\Microsoft Shared\OFFICE12\ACECORE.dll"
Dim jetExists As String = Environment.SystemDirectory & "\msjet40.dll"
If File.Exists(aceExists) Then 'If ACE provider is installed
'fExt contains the file extension of the file the user select
If fExt = "xlsx" Then
strConnection = New OleDbConnection("Provider='Microsoft.ACE.OLEDB.12.0'; Data Source='" & pathandFile & " '; " & "Extended Properties=""Excel 12.0;HDR=NO;IMEX=1"";")
ElseIf fExt = "xls" Then
strConnection = New OleDbConnection("Provider='Microsoft.ACE.OLEDB.12.0'; Data Source='" & pathandFile & " '; " & "Extended Properties=""Excel 8.0;HDR=NO;IMEX=1"";")
End If
ElseIf File.Exists(jetExists) Then 'If ACE is not found, determine if Jet is installed
If fExt = "xls" Then
strConnection = New OleDbConnection("Provider='Microsoft.JET.OLEDB.4.0'; Data Source='" & pathandFile & " '; " & "Extended Properties='Excel 8.0;HDR=No;IMEX=1';")
ElseIf fExt = "xlsx" Then
Dim er As String = "Can not read data from xlsx file format. Please install 2007 Office System Driver."
Dim dlgRes As DialogResult
dlgRes = MessageBox.Show(er, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
If Windows.Forms.DialogResult.OK Then
Me.fileImport() 'File open dialog box
End If
End If
Else
Dim er As String = "Could not find either Jet or Ace data providers. Please install 2007 Office System Driver."
Dim dlgRes As DialogResult
dlgRes = MessageBox.Show(er, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.Close()
End If
Last edited: