Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
AL AL is offline
external usenet poster
 
Posts: 37
Default Pass Parameter to Access Query

I'm using the following code to open a query in Microsoft
Access.

Sub Test()
Dim appAccess As New Access.Application

appAccess.OpenCurrentDatabase "c:\reports\test.mdb"
appAccess.DoCmd.OpenQuery "query3"

End Sub

I've made the query, query3 a parameter query and i would
like the query to pick up a parameter value from my Excel
worksheet. How might I do this? Thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 599
Default Pass Parameter to Access Query

Al

There's really no easy way to do that. First, why are you running the query
from inside Excel? There may be a better way to do what you are trying to
do.

If you must do it this way, there is one option that I can think of. Remove
the parameter from the Access query and rebuild the SQL of the QueryDef
object to include the cell's value in the criteria.

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"Al" wrote in message
...
I'm using the following code to open a query in Microsoft
Access.

Sub Test()
Dim appAccess As New Access.Application

appAccess.OpenCurrentDatabase "c:\reports\test.mdb"
appAccess.DoCmd.OpenQuery "query3"

End Sub

I've made the query, query3 a parameter query and i would
like the query to pick up a parameter value from my Excel
worksheet. How might I do this? Thanks in advance.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default Pass Parameter to Access Query

"Dick Kusleika" wrote in message ...

Remove
the parameter from the Access query and rebuild the SQL of the QueryDef
object to include the cell's value in the criteria.


Alternatively, assuming MS Query, keep the parameters and rebuild the SQL as e.g.

EXEC MyStoredProc 'paramter1', 'parameter2'

or the ODBC Direct syntax

{Call MyStoredProc('paramter1', 'parameter2')}

--
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Pass Parameter to Access Query

Hi Al,

As Dick said, unless you have to, I wouldn't recommend opening Access and
running the query using DoCmd. There's no reason to add the overhead of the
Access interface to Jet if you don't have to. You can do all of this using
ADO (or DAO). Basically, you set up a connection, then execute the query as
a command with parameters.

Here's an article that should get you started (it uses VBScript, which is
very similar to VBA):

http://support.microsoft.com/default...NoWebContent=1

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Al wrote:
I'm using the following code to open a query in Microsoft
Access.

Sub Test()
Dim appAccess As New Access.Application

appAccess.OpenCurrentDatabase "c:\reports\test.mdb"
appAccess.DoCmd.OpenQuery "query3"

End Sub

I've made the query, query3 a parameter query and i would
like the query to pick up a parameter value from my Excel
worksheet. How might I do this? Thanks in advance.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
pass parameter to access query Bill Manville Links and Linking in Excel 4 May 1st 23 03:45 AM
Pass date parameter into MS Query Richard Edwards Excel Discussion (Misc queries) 2 June 20th 08 11:43 AM
Is it possible to pass a parameter into IN operator in Query? DennisS Excel Discussion (Misc queries) 0 June 26th 07 09:27 AM
MS query--can it handle parameter queries from Access? Dave F Excel Discussion (Misc queries) 0 September 13th 06 02:41 PM
How to use a Access Query that as a parameter into Excel database query Karen Middleton Excel Discussion (Misc queries) 1 December 13th 04 07:54 PM


All times are GMT +1. The time now is 05:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"