Hi
I have set up a form to run a query, setting the following VBA to pick up values from the combo boxes in the form. The only problem is that I cant seem to get this working. When i press the command button it won't even get past the Dim db As Database line.
Private Sub Command10_Click()
On Error GoTo Errorhandler
Dim db As Database
Dim qd As QueryDef
Dim vWhere As Variant
Set db = CurrentDb()
On Error Resume Next
db.QueryDefs.Delete "qry_email2"
On Error GoTo 0
vWhere = Null
vWhere = vWhere & " AND [Status]=" + Me.cbostatustype
vWhere = vWhere & " AND [Substatus]=" + Me.cboSubstatus
vWhere = vWhere & " AND [PublicationName]=" + Me.cboPub1
vWhere = vWhere & " AND [PublicationName]=" + Me.cboPub2
vWhere = vWhere & " AND [PublicationName]=" + Me.cboPub3
If Nz(vWhere, "") = "" Then
MsgBox "There are no search criteria selected." & vbCrLf & vbCrLf & _
"Search Cancelled.", vbInformation, "Search Canceled."
Else
Set qd = db.CreateQueryDef("qry_email2", "SELECT * FROM tblgeneralcontactdetails WHERE " & _
Mid(vWhere, 6))
db.Close
Set db = Nothing
DoCmd.OpenQuery "qry_email2", acViewNormal, acReadOnly
Me.Command10.Requery
End Sub
help! I am now proper stuck with this.
Thanks in advance
Shapman
I have set up a form to run a query, setting the following VBA to pick up values from the combo boxes in the form. The only problem is that I cant seem to get this working. When i press the command button it won't even get past the Dim db As Database line.
Private Sub Command10_Click()
On Error GoTo Errorhandler
Dim db As Database
Dim qd As QueryDef
Dim vWhere As Variant
Set db = CurrentDb()
On Error Resume Next
db.QueryDefs.Delete "qry_email2"
On Error GoTo 0
vWhere = Null
vWhere = vWhere & " AND [Status]=" + Me.cbostatustype
vWhere = vWhere & " AND [Substatus]=" + Me.cboSubstatus
vWhere = vWhere & " AND [PublicationName]=" + Me.cboPub1
vWhere = vWhere & " AND [PublicationName]=" + Me.cboPub2
vWhere = vWhere & " AND [PublicationName]=" + Me.cboPub3
If Nz(vWhere, "") = "" Then
MsgBox "There are no search criteria selected." & vbCrLf & vbCrLf & _
"Search Cancelled.", vbInformation, "Search Canceled."
Else
Set qd = db.CreateQueryDef("qry_email2", "SELECT * FROM tblgeneralcontactdetails WHERE " & _
Mid(vWhere, 6))
db.Close
Set db = Nothing
DoCmd.OpenQuery "qry_email2", acViewNormal, acReadOnly
Me.Command10.Requery
End Sub
help! I am now proper stuck with this.
Thanks in advance
Shapman