Hello all! I am trying to setup a basic search parameters and I am new at this.
I read the article about how to use Querydefs and am trying to follow it as closely as possible. I gotten to a point where Access keeps returning the following message:
Run-Time Error 2001: You cancelled the previous operation.
Here is the code that I am running:
Dim db As DAO.Database
Dim QD As QueryDef
Dim where As Variant
Set db = CurrentDb()
On Error Resume Next
db.QueryDefs.Delete "Dynamic_Query"
On Error GoTo 0
where = Null
If IsNull(Drop_Point_s_) And IsNull(Text2) Then
MsgBox "You forgot to enter search parameter(s)", vbOKOnly
End If
If Drop_Point_s_ <> "" And Text2 <> "" Then
where = "[Dispatch Date]= '" & Text2.Text & "'"
where = where & " AND [Drop point(s)]= '" & Drop_Point_s_ & "'"
End If
If IsNull(Drop_Point_s_) Then
where = "[Forecast]![Dispatch Date]= '" & Text2 & "'"
End If
If IsNull(Text2) Then
where = "[Drop point(s)]= '" & Drop_Point_s_.Text & "'"
End If
MsgBox "Select * from Forecast where " & where
Set QD = db.CreateQueryDef("Dynamic_Query", "Select * from Forecast where " & where & ";")
DoCmd.OpenQuery "Dynamic_Query"
I'm sure that I am missing something, but I can't seem to pinpoint what is going on. Any help would be greatly appreciated!
Thanks!
Steve
I read the article about how to use Querydefs and am trying to follow it as closely as possible. I gotten to a point where Access keeps returning the following message:
Run-Time Error 2001: You cancelled the previous operation.
Here is the code that I am running:
Dim db As DAO.Database
Dim QD As QueryDef
Dim where As Variant
Set db = CurrentDb()
On Error Resume Next
db.QueryDefs.Delete "Dynamic_Query"
On Error GoTo 0
where = Null
If IsNull(Drop_Point_s_) And IsNull(Text2) Then
MsgBox "You forgot to enter search parameter(s)", vbOKOnly
End If
If Drop_Point_s_ <> "" And Text2 <> "" Then
where = "[Dispatch Date]= '" & Text2.Text & "'"
where = where & " AND [Drop point(s)]= '" & Drop_Point_s_ & "'"
End If
If IsNull(Drop_Point_s_) Then
where = "[Forecast]![Dispatch Date]= '" & Text2 & "'"
End If
If IsNull(Text2) Then
where = "[Drop point(s)]= '" & Drop_Point_s_.Text & "'"
End If
MsgBox "Select * from Forecast where " & where
Set QD = db.CreateQueryDef("Dynamic_Query", "Select * from Forecast where " & where & ";")
DoCmd.OpenQuery "Dynamic_Query"
I'm sure that I am missing something, but I can't seem to pinpoint what is going on. Any help would be greatly appreciated!
Thanks!
Steve