On the Fly Query Prob

E

Edgar Thoemmes

Hi

I am trying to use the code below to create a query on the fly, it is coming
up with the error 'You Cancelled the previous operation' on the following
line.
DoCmd.OpenQuery ("qrySearch")
Does anyone know what this error message means - Access help has no info.

Thanks in advance

Public Sub CmdSearch_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String

Set db = CurrentDb
Set qdf = db.QueryDefs("qrySearch")

If Me.chkAnnulled.Value = -1 Then
strAnnulled = "Yes"
Else
strAnnulled = "No"
End If

strSQL = "SELECT tbl_Contracts.SupplierID,
tbl_Contracts.ContractDescription, tbl_Contracts.StartDate, " & _
"tbl_Contracts.EndDate, tbl_Contracts.NoticePeriod,
tbl_Contracts.ReviewDate, tbl_Contracts.ContractNotes,
tbl_Contracts.AnnulledContract" & _
" FROM tbl_Contracts" & _
" WHERE tbl_Contracts.EndDate<Date()-" & StrDate & " AND
tbl_Contracts.AnnulledContract='" & strAnnulled & "';"

'Debug.Print strSQL

qdf.SQL = strSQL

DoCmd.OpenQuery ("qrySearch")

Set qdf = Nothing
Set db = Nothing

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top