If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
From VB .Net, how obtain ref to Access project?
From VB .Net, using either DAO or ADOX (or whatever else is available), how
can I obtain a reference to a database file created in Access? For example, I tried the following: Dim AccessApp As New Microsoft.Office.Interop.Access.Application AccessApp.OpenCurrentDatabase("C:\Documents and Settings\...\filename.mdb") Dim cat As ADOX.Catalog cat.ActiveConnection = AccessApp.CurrentProject.Connection The last statement gives me a "Object reference not set to an instance of an object" error. -- Ed |
#2
|
|||
|
|||
The immediate problem here is that you've declared the "cat" variable but
never instantiated it - you're missing a "Set cat = New ADOX.Catalog" line. Beyond that, you're mixing automation and data access, which are really two separate things. What is it you want to do - automate the Access application, or just get at the data from your .NET code? -- Brendan Reynolds (MVP) "Ed White" .(donotspam) wrote in message ... From VB .Net, using either DAO or ADOX (or whatever else is available), how can I obtain a reference to a database file created in Access? For example, I tried the following: Dim AccessApp As New Microsoft.Office.Interop.Access.Application AccessApp.OpenCurrentDatabase("C:\Documents and Settings\...\filename.mdb") Dim cat As ADOX.Catalog cat.ActiveConnection = AccessApp.CurrentProject.Connection The last statement gives me a "Object reference not set to an instance of an object" error. -- Ed |
#3
|
|||
|
|||
Essentially, I'm trying to do in VB .Net what is done in VBA under Access,
i.e. I'm trying to write code in VB .Net to manipulate a database using the same/similar commands available in Access VBA. I see the commands in the VB ..Net Object Library (after adding the appropriate references), I just can't get the commands to talk to the approrpiate .mdb file. For example, in my prior post "How to add new table programatically" on 2/2/05 which you responded to, you told me how to add new tables using DAO, ADOX, and DDL. I got the DDL to work, but I couldn't figure out how to access the .mdb file in DAO or ADOX. "Brendan Reynolds" wrote: The immediate problem here is that you've declared the "cat" variable but never instantiated it - you're missing a "Set cat = New ADOX.Catalog" line. Beyond that, you're mixing automation and data access, which are really two separate things. What is it you want to do - automate the Access application, or just get at the data from your .NET code? -- Brendan Reynolds (MVP) "Ed White" .(donotspam) wrote in message ... From VB .Net, using either DAO or ADOX (or whatever else is available), how can I obtain a reference to a database file created in Access? For example, I tried the following: Dim AccessApp As New Microsoft.Office.Interop.Access.Application AccessApp.OpenCurrentDatabase("C:\Documents and Settings\...\filename.mdb") Dim cat As ADOX.Catalog cat.ActiveConnection = AccessApp.CurrentProject.Connection The last statement gives me a "Object reference not set to an instance of an object" error. -- Ed |
#4
|
|||
|
|||
I'm afraid I won't be able to help you with that, Ed. You could try asking
in a .NET newsgroup. I think the answer will probably be that this approach is not practical, but who knows, I could be wrong. -- Brendan Reynolds (MVP) "Ed White" .(donotspam) wrote in message ... Essentially, I'm trying to do in VB .Net what is done in VBA under Access, i.e. I'm trying to write code in VB .Net to manipulate a database using the same/similar commands available in Access VBA. I see the commands in the VB .Net Object Library (after adding the appropriate references), I just can't get the commands to talk to the approrpiate .mdb file. For example, in my prior post "How to add new table programatically" on 2/2/05 which you responded to, you told me how to add new tables using DAO, ADOX, and DDL. I got the DDL to work, but I couldn't figure out how to access the .mdb file in DAO or ADOX. "Brendan Reynolds" wrote: The immediate problem here is that you've declared the "cat" variable but never instantiated it - you're missing a "Set cat = New ADOX.Catalog" line. Beyond that, you're mixing automation and data access, which are really two separate things. What is it you want to do - automate the Access application, or just get at the data from your .NET code? -- Brendan Reynolds (MVP) "Ed White" .(donotspam) wrote in message ... From VB .Net, using either DAO or ADOX (or whatever else is available), how can I obtain a reference to a database file created in Access? For example, I tried the following: Dim AccessApp As New Microsoft.Office.Interop.Access.Application AccessApp.OpenCurrentDatabase("C:\Documents and Settings\...\filename.mdb") Dim cat As ADOX.Catalog cat.ActiveConnection = AccessApp.CurrentProject.Connection The last statement gives me a "Object reference not set to an instance of an object" error. -- Ed |
#5
|
|||
|
|||
Ed White (donotspam) wrote: I got the DDL to work, but I couldn't figure out how to access the .mdb file in DAO or ADOX. Then use DDL g. You could try searching the google groups Usenet archive for examples e.g. http://tinyurl.com/4saap Jamie. -- |
#6
|
|||
|
|||
Ed,
You have opened database correctly, but forgot to initialize your ADOX.Catalog object - hence the error. HTH -----Original Message----- From VB .Net, using either DAO or ADOX (or whatever else is available), how can I obtain a reference to a database file created in Access? For example, I tried the following: Dim AccessApp As New Microsoft.Office.Interop.Access.Application AccessApp.OpenCurrentDatabase("C:\Documents and Settings\...\filename.mdb") Dim cat As ADOX.Catalog cat.ActiveConnection = AccessApp.CurrentProject.Connection The last statement gives me a "Object reference not set to an instance of an object" error. -- Ed . |
#7
|
|||
|
|||
I just re-read your original post. The problem may be a flawed approach
on your part. You seem to be automating the MS Access app and using it to opening a file, simply to obtain a reference/pointer to an internal instance of an ADO Connection (note not an OleDb Connection). There is no need to do this when you can instead create an *external* connection to the database. Jamie. -- |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Access Error Message when opening database | eah | General Discussion | 3 | January 26th, 2005 11:04 AM |
Using Access 2000 with VB .Net | Roger Stenson | New Users | 0 | January 13th, 2005 06:56 PM |
Access and VB | HS1 | General Discussion | 2 | September 9th, 2004 09:01 PM |
Signing a VBA mde/mdb Access 2003 | John Buckett | General Discussion | 3 | July 3rd, 2004 09:14 PM |