470,561 Members | 2,210 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,561 developers. It's quick & easy.

Pass in a Parameter into an Openrecordset

Hi

I am using the openrecordet in the Ms Access to open saved queries I have in my database. I am trying to pass a parameter into the openrecordset the query has to use.

For example the query is a list of info for machine for two users and I want to open the saved query and pass in parameter to only show one of the users info.

I am using the following code.

Expand|Select|Wrap|Line Numbers
  1. dim dbs as database
  2.  
  3. dim rs_info as recordset
  4.  
  5. set dbs = currentdb()
  6.  
  7. set ts_info = dbs.openrecordset("user_info")
"user_info" is the name of the save query in the database.

I would be great if someone would be able to help

Thanks
May 25 '07 #1
1 6538
sajuk
9
Hi
You can use code below to manipulate your query.

Expand|Select|Wrap|Line Numbers
  1. Dim db As Database
  2. Dim qdf As QueryDef
  3. Dim prm As Parameter
  4. Dim rs As Recordset
  5.  
  6.  
  7. Set db = CurrentDb
  8. Set qdf = db.QueryDefs("YOURQUERYNAME")
  9.  
  10.     For Each prm In qdf.Parameters
  11.             prm.Value = Eval(prm.Name)
  12.     Next prm
  13.  
  14. Set rs = qdf.OpenRecordset(dbOpenDynaset)
  15.  
  16.  
  17.  
  18.             rs.MoveFirst
  19.  
  20.         Do Until rs.EOF
  21.  
  22. 'Manipulate your query here           
  23.  
  24.             rs.MoveNext
  25.  
  26.                 Loop
  27.  
  28. rs.Close
May 25 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Zlatko Matiś | last post: by
2 posts views Thread by BillCo | last post: by
8 posts views Thread by hbean | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.