JCJG
asked on
Excel 2007: Passing value from Excel to Access query
Hi, I use the following code to execute an Access query with from Excel. Then an input box pop up require user to enter a criteria for the query. I'd like to automatically pass a value from Excel to the query criteria. The value is stored in cell E5 or named range "Input" on the Excel file. How do I do that? Thanks.
Sub RunAccessQuery()
Dim acObj As Object
Set acObj = CreateObject("Access.Appli cation")
acObj.OpenCurrentDatabase "C:\Documents and Settings\Work\DB.accdb"
acObj.DoCmd.OpenQuery ("qry_01")
acObj.CloseCurrentDatabase
Set acObj = Nothing
End Sub
Sub RunAccessQuery()
Dim acObj As Object
Set acObj = CreateObject("Access.Appli
acObj.OpenCurrentDatabase "C:\Documents and Settings\Work\DB.accdb"
acObj.DoCmd.OpenQuery ("qry_01")
acObj.CloseCurrentDatabase
Set acObj = Nothing
End Sub
ASKER
Hi, I got an error message saying the Access table already exist. I think it is because the query I executed is a make-table query and the existing table needs to be replaced. How to fix it?
In addition, can you help me with a second set of code to run an Access macro instead?
Thanks!
In addition, can you help me with a second set of code to run an Access macro instead?
Thanks!
ASKER
Actually I have one more question. I'd like expand the criteria from cell E5 to E5:E6. Is it doable? Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help!
Give this code a shot.
Open in new window
Hope this helps,
pT72