By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,389 Members | 2,052 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,389 IT Pros & Developers. It's quick & easy.

How Do I creat a query in VB on the fly

100+
P: 147
I want to create a sql qry in vb that will give me info that I can use further down in the code.

I want to access the fields Rank and HireDate in my query qryEmployees for the EmployeeID used in my form that I am running the code from (these fields are not used in the form but EmployeeID from the same query is). I then want to use the values obtained freom these fields in an If statement in my code.

Thanks
Dan
Jan 19 '09 #1
Share this Question
Share on Google+
4 Replies


DonRayner
Expert 100+
P: 489
Warning this is air code
Replace YourTableName, YourForm and YourControl with your own names.

Expand|Select|Wrap|Line Numbers
  1. dim db as dao.database, rs as dao.recordset
  2. set db = currentdb()
  3. set rs = db.openrecordset("YourTableName")
  4. rs.movefirst
  5. do while not rs.eof
  6. if rs!EmployeeID = forms!YourForm!YourControl then
  7.  
  8. add your code here
  9.  
  10. rs.movelast
  11. else
  12. rs.movenext
  13. end if
  14. loop
  15.  
  16. rs.close
  17. set rs = nothing
  18. set db = nothing
  19.  
  20. rest of your code here
  21.  
  22.  
Jan 19 '09 #2

100+
P: 147
Thank You! that was it!!!!
Jan 20 '09 #3

DonRayner
Expert 100+
P: 489
You're quite welcome, glad I could help.
Jan 20 '09 #4

NeoPa
Expert Mod 15k+
P: 31,494
I suspect you are better off simply using the DLookup() function.
Jan 20 '09 #5

Post your reply

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