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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Beginning VBA/Access/SQL question

Status
Not open for further replies.

TurboWaffle

Programmer
Aug 29, 2002
2
US
I'm new to Access and VBA. I've had a lot of experience with PHP and MySQL, but none with VB before. I'm trying to figure out how to execute a select query and get a given part of the result set. I found DoCmd.RunSQL, but it says it's only for action's (Update, Delete, et. al). I'd be happy to RTFM but for the life of me I can't find an example of what I want to do. Can someone give me an example or point me to some resource that might help me? Thanks for your time,

-Chris
 
In order to run a Select Query in VBA I use the following code.


Dim Mydbs as database, Myrs a srecordset
Set Mydbs= Currentdb
Set Myrs=Mydbs.Openrecordset("qrySelect")
myrs.Movefirst

This "qrySelect" is the name of the query to run (or you could code the query directly in SQL).

You can move to subsequent records by

Myrs.MoveNext


You can test for End Of File with

Myrs.EOF (True or false)

Individual fields are accessed from myrs!fieldname

(for example a field in your query called DateTime would be myrs!DateTime)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top