easy ADO error when opening catalog 'reference not set'
-
Dim DBPath As String Dim ADOXcat As New ADOX.Catalog Dim sCreateString As String DBPath = System.Windows.Forms.Application.StartupPath() sCreateString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DBPath & "\New07ADB.accdb;Jet OLEDB:Database Password=admin;" 'for Access 2007 Try 'Create DB ADOXcat.Create(sCreateString) Catch ex As System.Runtime.InteropServices.COMException 'create DB failed MsgBox(ex.Message(), MsgBoxStyle.Critical, "Failed to create database") Finally ADOXcat = Nothing End Try Dim ADOXtable As New ADOX.Table(), _ ADOXindex As New ADOX.Index(), _ Con As New ADODB.Connection() Try 'connect and insert tables Con.Open("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DBPath & "\New07ADB.accdb;Jet OLEDB:Database Password=admin;") 'for 2007 MsgBox(Con.Errors().Count.ToString()) 'Displays 0 Errors MsgBox(Con.State.ToString()) 'Displays 1 representing an open connection 'Open the Catalog ADOXcat.ActiveConnection = Con 'Object reference not set to an instance of an object. I know this error usally gets generated when using a null object but if I receive no errors from opening the connection then 'Con' shouldnt be null right? Any help on this is greatly appreshated.
-
Dim DBPath As String Dim ADOXcat As New ADOX.Catalog Dim sCreateString As String DBPath = System.Windows.Forms.Application.StartupPath() sCreateString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DBPath & "\New07ADB.accdb;Jet OLEDB:Database Password=admin;" 'for Access 2007 Try 'Create DB ADOXcat.Create(sCreateString) Catch ex As System.Runtime.InteropServices.COMException 'create DB failed MsgBox(ex.Message(), MsgBoxStyle.Critical, "Failed to create database") Finally ADOXcat = Nothing End Try Dim ADOXtable As New ADOX.Table(), _ ADOXindex As New ADOX.Index(), _ Con As New ADODB.Connection() Try 'connect and insert tables Con.Open("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DBPath & "\New07ADB.accdb;Jet OLEDB:Database Password=admin;") 'for 2007 MsgBox(Con.Errors().Count.ToString()) 'Displays 0 Errors MsgBox(Con.State.ToString()) 'Displays 1 representing an open connection 'Open the Catalog ADOXcat.ActiveConnection = Con 'Object reference not set to an instance of an object. I know this error usally gets generated when using a null object but if I receive no errors from opening the connection then 'Con' shouldnt be null right? Any help on this is greatly appreshated.
Your con is fine, it is the ADOXCat that is not instantiated!
Quote from Great Outdoors: its a confident traveller who farts in India