troubleshooting Question

Open form in Datasheet view using date and listbox criteria

Avatar of leezac
leezac asked on
Microsoft Access
2 Comments1 Solution598 ViewsLast Modified:
I have a form and a button where I want to enter dates and select from a list box and be open to open a form in Data Sheet view.  I am using the code below, but is not working.
Thanks in advance.

Private Sub Command44_Click()
Dim stSQL As String
        Dim i
    Dim strCrit As String
    Dim strCritStatus As String
    Dim strCritDate As String

    strCritDate = "[Live Date] BETWEEN #" & Nz(Me.TxtToDate, #1/1/1900#) & "# AND #" & Nz(Me.TxtFromDate, #1/1/2100#) & "# "
If Me.listboxstatus.ItemsSelected.Count = 0 Then
        strCritStatus = ""
        strCritStatus = "AND [Status] IN ("
        For i = 0 To Me.listboxstatus.ItemsSelected.Count - 1
            strCritStatus = strCritStatus & "'" & Me.listboxstatus.ItemData(Me.listboxstatus.ItemsSelected.Item(i)) & "',"
        strCritStatus = Left(strCritStatus, Len(strCritStatus) - 1) & ")"
    End If
    strCrit = strCritDate & strCritStatus
    DoCmd.OpenForm "frmcustodyDV", acFormDS, WhereCondition:=strCritDate
End Sub
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros