cooldisk2005
Technical User
All,
I have the following code:
How do I modify the code to not show a record in the results if the dateEntered field has nothing in it?
I have the following code:
Code:
Private Sub cmdSearch_Click()
'Set the Dimensions of the Module
Dim strSQL As String, strOrder As String, strWhere As String
Dim dbNm As Database
Dim qryDef As QueryDef
Set dbNm = CurrentDb()
'Constant Select statement for the Query definition
'Constant Select statement for the Query definition
strSQL = "SELECT tbl_showmoney.regID, tbl_showmoney.dateEntered, tbl_showmoney.name, tbl_showmoney.company, tbl_showmoney.mailingAddress, tbl_showmoney.city, tbl_showmoney.stateCan, tbl_showmoney.zipCode, tbl_showmoney.country, tbl_showmoney.telephoneNo, tbl_showmoney.faxNo, tbl_showmoney.email, tbl_showmoney.contype, tbl_showmoney.totalCamp, tbl_showmoney.idMtg, tbl_showmoney.day1Con, tbl_showmoney.day2Con, tbl_showmoney.day3Con, tbl_showmoney.day4Con, tbl_showmoney.day5Con, tbl_showmoney.day6Con, tbl_showmoney.day7Con, tbl_showmoney.bkstCount, tbl_showmoney.lunchTickets, tbl_showmoney.dinnerTickets, tbl_showmoney.drinkTickets " & _
"FROM tbl_showmoney"
strWhere = "WHERE"
strOrder = " ORDER BY tbl_showmoney.regID;"
'Set the WHERE clause for the QueryDef if information has been entered into a field on the form
If Not IsNull(Me.name1) Then '<--If the textbox txtFName contains no data THEN do nothing
strWhere = strWhere & " (tbl_showmoney.name) Like '*" & Me.name1 & "*' AND" '<--otherwise, apply the LIKE statment to the QueryDef
End If
If Not IsNull(Me.company) Then
strWhere = strWhere & " (tbl_showmoney.company) Like '*" & Me.company & "*' AND"
End If
If Not IsNull(Me.contype) Then
strWhere = strWhere & " (tbl_showmoney.contype) Like '*" & Me.contype & "*' AND"
End If
'Remove the last AND from the SQL statment
strWhere = Mid(strWhere, 1, Len(strWhere) - 4)
'Pass the QueryDef to the query
Set qryDef = dbNm.QueryDefs("qry_showmoney")
qryDef.SQL = strSQL & " " & strWhere & "" & strOrder
'Open the Query
Dim dbs As DAO.Database, rst As DAO.Recordset
Dim rsCnt As Integer 'the counter
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("qry_showmoney", dbOpenDynaset)
With rst
If .RecordCount > 0 Then 'What you want done
DoCmd.OpenForm ("frm_registrationDeskSearch"), acNormal, "[regID]"
DoCmd.Close acForm, "frm_search"
Else
MsgBox "There is no data that meets your criteria. Please try again.", vbOKOnly, "No Data Found" 'What you want done
name1.Value = ""
company.Value = ""
contype.Value = ""
name1.SetFocus
End If
End With
Set dbs = Nothing
Set rst = Nothing
End Sub
How do I modify the code to not show a record in the results if the dateEntered field has nothing in it?