Setting criteria for my form (in VBA), why isn't this working?

MsLady

Traumatized by Access
Local time
Today, 11:17
Joined
Jun 14, 2004
Messages
438
Does anyone have any idea what to do here, cos i am stuck.
I am trying to get a To and From Date as a criteria for my resultsform from this form, and it doesn't seem to work. When i comment out the date criteria (see color red), the form searches fine with the other criteria. Some please help me check the part in red. Thanks.


Code:
Private Sub cmdFindJobs_Click()

    Dim stDocName As String
    Dim stCriteria As String
    
    stDocName = "subfrmSearchResults"
    stCriteria = "[jobId] like " & "'*'"

    [color=red]If Not IsNull(Me![cboDate]) Then stCriteria = stCriteria & " and ([timeInFD]>=" & "'" & Me![cboDate] & "' and [timeInFD]<=" & "'" & Me![cboDate2] & "'" & ")"
        'If Not IsNull(Me![cboDate]) Then stCriteria = stCriteria & " and [timeInFD] between " & "'" & Me![cboDate] & "' and " & "'" & Me![cboDate2] & "'" [/color]
    If Not IsNull(Me![shift]) Then stCriteria = stCriteria & " and [shift] like " & "'" & Me![shift] & "'"
    If Not IsNull(Me![status]) Then stCriteria = stCriteria & " and [status] like " & "'" & Me![status] & "'"
    If Not IsNull(Me![requester]) Then stCriteria = stCriteria & " and [requestedBy] like " & "'*" & Me![requester] & "*'"
    If Not IsNull(Me![clientmatter]) Then stCriteria = stCriteria & " and [clientmatter] like " & "'*" & Me![clientmatter] & "*'"
DoCmd.OpenForm stDocName, acFormDS, , stCriteria

End Sub

I am using access 2000. I have spent so much time twiking and i am just not getting anywhere. Thanks buddies :)
 
Dates and times need to be surrounded by # rather than '.
 
pbaldy said:
Dates and times need to be surrounded by # rather than '.
ok coool!! that does it. thanks baldy :D
 

Users who are viewing this thread

Back
Top Bottom