Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to run access macro from VB (DAO or ADO)? 2

Status
Not open for further replies.

Dan01

Programmer
Jun 14, 2001
439
US
Is there a DoCmd equivalent in DAO or ADO that allows me to run macros or queries from a VB program? Thanks, Dan.
 
Hi,

I don't know about macros but you can execute SQL statements like queries. DAO has the Querydefs collection to allow the use of queries in an Access DB. ADO, which is better, can execute the equivalent SQL statewments.

dim conn as connection
dim rs as recordset
dim strConnect as string

strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=[Source];Persist Security Info=False"

strConnect = Replace(strConnect, "[Source]", "C:\db1.mdb

Conn.Open (strConnect)
rs.open "SELECT * FROM Table1", conn
set conn = nothing: set rs = nothing

Have a good one!
BK
 
Thanks BK for the example. Will ADO also allow many query types such as UPDATE queries? Dan.
 
Dan

I just went through the process of trying to run a function in an Access module from VB using ADO. Unfortunately it looks like it can't be done. Queries are ok though.

Mike When you call out for help in the darkness, and you hear a voice in return, you're probably just talking to yourself again!
 
Yes any standard SQL query will run via ADO Let me know if this helps

Check out FAQ222-2244
'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
To run an Access Macro with-in a VB program you will need to add a reference to the Microsoft Access Object library, or just create the object.
Once done, you can use an object variable on it and then execute the DoCmd method with-in VB.
While this works fine, you may not distribute the Access object with-out the proper license (wouldn't work anyways if ACCESS was not on the client pc).
You may however reference the object with-in your project, and, if the client PC has a copy of ACCESS on it, then there is no problem....if not, then you will not be able to do what you want.
 
Thanks guys. You all posted good stuff. I created an object and then used obj.DoCmd to run the macro. Dan.
 
Thanks guys. You all posted good stuff. I created an object and then used obj.DoCmd to run the macro. Dan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top