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

Passing Parameter Query Value in DoCmd

Status
Not open for further replies.

MTBChik

Technical User
Jun 19, 2001
58
US
I have set up some code that will automatically generate an email using Groupwise. The problem is, I need to pass the user defined parameter in the DoCmd part of the VB.

Here's what I've got:
Private Sub cmdGO_Click()

On Local Error GoTo Some_Err

Dim MyDB As Database, RS As Recordset
Dim strBody As String, lngCount As Long, lngRSCount As Long
Dim strTO As String
Dim strSubject As String
Dim intMessageID As Integer

'DoCmd.RunCommand acCmdSaveRecord
Set MyDB = DBEngine.Workspaces(0).Databases(0)

Me!txtProgress = Null

Set RS = MyDB.OpenRecordset _
("qryLateResults")


At this point, it kicks to my error handler with the message "Error(3061) Too few parameters. Expected 1"

How can I allow the user to input the parameter and pass it to the query so that it will run the query properly (I don't wish to send out my entire database of events....)

Thanks,
MTB Chick
 
Try this:

Dim db As Database, qd As QueryDef, pr As Parameter, rs As Recordset
Set db = CurrentDb
Set qd = db.QueryDefs(QueryName)
For Each pr In qd.Parameters
pr = Eval(pr.Name)
Next
Set rs = qd.OpenRecordset

rs.Close
Set rs = Nothing
Set qd = Nothing
Set db = Nothing


James Goodman MCP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top