B
Bear S.
My problem is that on the .add of the with querytables line, I get the
unhandled exception with the error that "Object reference not set to an
instance of an object." However, when i set QueryTables as NEW MS..... it
won't even compile. It is of note that Microsoft.Office.Interop.Excel lists
QueryTables (with an "s") as a public interface and QueryTable (without an
"s") as a public class
public class program
public shared Excel as new Microsoft.Office.Interop.Excel.Application
end class
public class AccessDB
Dim QueryTables As Microsoft.Office.Interop.Excel.QueryTables
Public Sub Get_Data(ByVal family As String, ByVal Table As String)
'
' To be used to get data from the database
'
Dim str_DataBase As String = DBPath & family & ".mdb\"
Dim connection_string As String = _
"OLEDB;" & _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Password=" & Chr(34) & Chr(34) & ";" & _
"User ID=Admin;" & _
"Data Source=" & Chr(34) & str_DataBase & Chr(34) & ";" & _
"Mode=Share Deny Write;" & _
"Extended Properties=" & Chr(34) & Chr(34) & ";" & _
"Jet OLEDB:System database=" & Chr(34) & Chr(34) & ";" & _
"Jet OLEDB:Regis" & _
"try Path=" & Chr(34) & Chr(34) & ";" & _
"Jet OLEDBatabase Password=" & Chr(34) & Chr(34) & ";" & _
"Jet OLEDB:Engine Type=4;" & _
"Jet OLEDBatabase Locking Mode=0;" & _
"Jet OLEDB:Global Partial Bulk Ops=2;" & _
"Jet OLEDB:Global Bulk Transactions=1;" & _
"Jet OLEDB:New Database Password=" & Chr(34) & Chr(34) & ";"
& _
"Jet OLEDB:Create System Database=False;" & _
"Jet OLEDB:Encrypt Database=False;" & _
"Jet OLEDBon't Copy Locale on Compact=False;" & _
"Jet OLEDB:Compact Without Replica Repair=False;" & _
"Jet OLEDB:SFP=False"
With QueryTables
.Add(Connection:=connection_string,
Destination:=Program.Excel.Range("A1"))
.CommandType = XlCmdType.xlCmdTable
.CommandText = Table
.Name = family
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = Program.Excel.xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceDataFile = str_DataBase
.Refresh(BackgroundQuery:=False)
End With
End Sub
end class
unhandled exception with the error that "Object reference not set to an
instance of an object." However, when i set QueryTables as NEW MS..... it
won't even compile. It is of note that Microsoft.Office.Interop.Excel lists
QueryTables (with an "s") as a public interface and QueryTable (without an
"s") as a public class
public class program
public shared Excel as new Microsoft.Office.Interop.Excel.Application
end class
public class AccessDB
Dim QueryTables As Microsoft.Office.Interop.Excel.QueryTables
Public Sub Get_Data(ByVal family As String, ByVal Table As String)
'
' To be used to get data from the database
'
Dim str_DataBase As String = DBPath & family & ".mdb\"
Dim connection_string As String = _
"OLEDB;" & _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Password=" & Chr(34) & Chr(34) & ";" & _
"User ID=Admin;" & _
"Data Source=" & Chr(34) & str_DataBase & Chr(34) & ";" & _
"Mode=Share Deny Write;" & _
"Extended Properties=" & Chr(34) & Chr(34) & ";" & _
"Jet OLEDB:System database=" & Chr(34) & Chr(34) & ";" & _
"Jet OLEDB:Regis" & _
"try Path=" & Chr(34) & Chr(34) & ";" & _
"Jet OLEDBatabase Password=" & Chr(34) & Chr(34) & ";" & _
"Jet OLEDB:Engine Type=4;" & _
"Jet OLEDBatabase Locking Mode=0;" & _
"Jet OLEDB:Global Partial Bulk Ops=2;" & _
"Jet OLEDB:Global Bulk Transactions=1;" & _
"Jet OLEDB:New Database Password=" & Chr(34) & Chr(34) & ";"
& _
"Jet OLEDB:Create System Database=False;" & _
"Jet OLEDB:Encrypt Database=False;" & _
"Jet OLEDBon't Copy Locale on Compact=False;" & _
"Jet OLEDB:Compact Without Replica Repair=False;" & _
"Jet OLEDB:SFP=False"
With QueryTables
.Add(Connection:=connection_string,
Destination:=Program.Excel.Range("A1"))
.CommandType = XlCmdType.xlCmdTable
.CommandText = Table
.Name = family
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = Program.Excel.xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceDataFile = str_DataBase
.Refresh(BackgroundQuery:=False)
End With
End Sub
end class