DerekMcDonald
Technical User
Hi! It seems like this should be simple, but...
I have a permanent query where I'm trying to set the criteria through functions that grab data from a form. Let's take the [Date] field as an example. In the query, the function getDate() is in the criteria field.
If the user chooses "Before" in cmbDate, I'd like the function to send "<#" & me.txtDate & "#" to the query's criteria field.
If I only send me.txtDate, it works fine. But if I try to send a concatenated value, I get "Run time error 2001. You cancelled the previous operation." Typing <#1/1/00# directly into the query's criteria field does not generate errors, so in theory the string should look like what I'm trying to send.
Here's my code:
In a public module:
Public varDate as Variant
Public Function getDate()
getDate = varDate
End Function
In the form's module:
Private Sub cmdQuery_Click()
If Me.cmbDate = "Before" Then
varDate = "<" & "#" & Me.txtPurDate & "#"
End If
DoCmd.OpenQuery "qryParams", acNormal, acEdit
End Sub
The DoCmd line brings the whole thing to a halt.
So how do I correctly set the query's criteria based on a function without generating these errors?
This is driving me crazy! Thanks!
I have a permanent query where I'm trying to set the criteria through functions that grab data from a form. Let's take the [Date] field as an example. In the query, the function getDate() is in the criteria field.
If the user chooses "Before" in cmbDate, I'd like the function to send "<#" & me.txtDate & "#" to the query's criteria field.
If I only send me.txtDate, it works fine. But if I try to send a concatenated value, I get "Run time error 2001. You cancelled the previous operation." Typing <#1/1/00# directly into the query's criteria field does not generate errors, so in theory the string should look like what I'm trying to send.
Here's my code:
In a public module:
Public varDate as Variant
Public Function getDate()
getDate = varDate
End Function
In the form's module:
Private Sub cmdQuery_Click()
If Me.cmbDate = "Before" Then
varDate = "<" & "#" & Me.txtPurDate & "#"
End If
DoCmd.OpenQuery "qryParams", acNormal, acEdit
End Sub
The DoCmd line brings the whole thing to a halt.
So how do I correctly set the query's criteria based on a function without generating these errors?
This is driving me crazy! Thanks!