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

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

Brendan Reynolds

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?
 
G

Guest

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

Brendan Reynolds

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

Sergey Poberezovskiy

Ed,

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

HTH
 
O

onedaywhen

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.

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top