Recordset problem

Martyh

Registered User.
Local time
Today, 02:14
Joined
May 2, 2000
Messages
196
People,
I have a code tidbit that I can't seem to make work...

**************************************************
Dim dbs As DAO.Database, qdf As QueryDef, rst As Recordset
dim strSql as string

Set dbs = CurrentDb

strSQL = "Select * from tblLocation"

Set qdf = dbs.CreateQueryDef("ParameterQuery", strSQL)

qdf.Execute 'down to here everything works

'What's the problem with the next statement ? I am trying to open the recordset based on the query definition to see if there are any records. It is this statement that my program fails at! Is there some other way to get at the number of records in that set? ( I Forgot to add --- runtime error code 3219 --- Invalid operation ... Why?
'---------------------------------------------
Set rst = qdf.OpenRecordset

If rst.RecordCount <= 0 Then
If strType = "NE" Then
MsgBox ("You have no records in the table within " & dblRadiusR & " metres of this site.")
End If
End If

GoTo Exit_cmdFindWells_Click
Else
Call NewIndex("tblTEMP", "Radius")
DoCmd.OpenForm stDocName

End If
************************************************************
 
Last edited:
Sorry if this is just being obnoxious and you just didn't include it here, but you might want to dim strSql too.
 
Isn't the Execute method only available for action queries?
 
Whoops --- you are correct !

(whoops I seem to be editing the message all the time)

--- the strSQL string should read "Select * into Test1 .... "
--- sorry there is an enormous amount of code so I just pared it down ...

There are some parameters in the qdf too ... but I thought that they were not important to the code working properly --- maybe they are!!!

I thought that I was doing something wrong right at the statement that I couldn't see.

http://www.access-programmers.co.uk/forums/images/icons/icon11.gif
Red face
 
Marty,

Shouldn't you do a qdf.Close before you try to open it?

Wayne
 
If you don't need to see the results of the query then just use:

Set qdf = dbs.CreateQueryDef("ParameterQuery", strSql)
Set rst = qdf.OpenRecordset
If rst.EOF Then

Instead of:

Set qdf = dbs.CreateQueryDef("ParameterQuery", strSQL)
qdf.Execute
Set rst = qdf.OpenRecordset
If rst.RecordCount <= 0 Then
 

Users who are viewing this thread

Back
Top Bottom