From VB .Net, how obtain ref to Access project?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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?
 
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.
 
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.
 
Ed,

You have opened database correctly, but forgot to
initialize your ADOX.Catalog object - hence the error.

HTH
 
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.

--
 
Back
Top