Avatar of leezac
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 = ""
    Else
        strCritStatus = "AND [Status] IN ("
        For i = 0 To Me.listboxstatus.ItemsSelected.Count - 1
            strCritStatus = strCritStatus & "'" & Me.listboxstatus.ItemData(Me.listboxstatus.ItemsSelected.Item(i)) & "',"
        Next
        strCritStatus = Left(strCritStatus, Len(strCritStatus) - 1) & ")"
    End If
   
    strCrit = strCritDate & strCritStatus
    DoCmd.OpenForm "frmcustodyDV", acFormDS, WhereCondition:=strCritDate
End Sub
db17.zip
Microsoft Access

Avatar of undefined
Last Comment
leezac

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
mbizup

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
or
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
leezac

ASKER
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