Avatar of leezac
 asked on

Open form in Datasheet view using date and listbox criteria

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
Microsoft Access

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

That worked!!!
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy