DIsplaying a Temporary QueryDef in Access

Karsten
09-28-2000, 10:36 AM
Hello all! I was hoping I might get some help on this...

In the code module of an Access form I have a command button that runs the following code:
___________________________________

Private Sub cmdQuery_Click()
Dim db As Database
Dim NoEMails As QueryDef

Set db = CurrentDb

Select Case optRecipients
Case 1
Set NoEMails = db.CreateQueryDef("")
NoEMails.SQL = "SELECT (sql goes here)"
'Set recNoEmails = NoEMails.OpenRecordset
Case 2
...
End Select

db.close
Set db = nothing
___________________________________

How do I display the results of the temporary querydef? I don't want to save the query and do an .openquery. I'm stuck on this --- any help?

Thanks!

whelanp
09-28-2000, 11:30 AM
I'm assuming you want the display the results in some sort of grid on your current form.

You dont need to use a query(def). They should only be used for action queries (INSERT, UPDATE, DELETE...)

Try the folowing

Dim dbCur as Database
dim rsTmp as recordset
dim strSQL as string

set db = currentdb()

strSQL = "SELECT * FROM tblMyData"

set rsTmp = dbCurr.OpenRecordset(strSQL)

You now have your recordset.

Put a grid or whatever control you want to use to display your data on the form (MyControl).

With MyControl
.RecordSource = rsTmp
end with

Thats about it.....

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum