retrieving parameter query records

Penmore

Registered User.
Local time
Today, 14:23
Joined
Apr 2, 2006
Messages
27
Having spent a not inconsiderable amount of time searching for the information a running parameter queries in VBA, I eventually found the answer tucked away in this thread and posted by Pat Hartman (thank you Pat).
querydef openrecordset. I was hoping to find the answer to my question by using one of the following phrases but most of the titles that come from the search have meaningless titles which are unhelpful.
retrieving parameter query records
reading parameter query records
running parameter queries

So, I’ve decided to post this thread to perhaps help other members find their answer a little quicker:

The Area variable is read from a flat text file.
The CurrentArea is an existing parameter query with the criteria field Like [searcharea]
txtName is a existing field in the parameter query CurrentArea
There are various Do While loops that control the reading of the Area text file.


Dim Area As String, OutputAreaName As String, dbs As Database, rs As Recordset
Dim qdf As QueryDef, QueryString As String

QueryString = Area & "*"
Set dbs = DBEngine(0)(0)
Set qdf = dbs.QueryDefs("CurrentArea")
qdf.Parameters![searcharea] = QueryString
Set rs = qdf.OpenRecordset
rs.MoveFirst

MsgBox rs!txtName
.
.
. additional coding as necessary for fields in the parameter query
.
.
.
rs.Close


~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It might be appropriate if Mods or Admin could sometimes change the titles of various posts to make them more meaningful for people doing searches for solutions and easier to find the appropriate thread in the search results :confused:
 

Users who are viewing this thread

Back
Top Bottom