Link to home
Start Free TrialLog in
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
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of leezac
leezac

ASKER

That worked!!!