C
Cathleen
I have a search form with the following code in the search button's OnClick
event. It works great as long as the user selects one or more items in the
multi-select list box [lstStationID]. If nothing is selected, the where
string has unneccsary characters on the end of it. So, I think I could do one
of two things: 1) If nothing is selected, have code that chops off more
characters at the end of the where string or 2) require the user to select
one or more items and have a message box appear if the user clicks the search
button without selecting anything. However, I am having trouble getting
either of these methods to work. Does anyone have any suggestions on how to
handle this?
Thank you!
Private Sub cmdInSituFilter_Click()
Dim StrWhere As String
Dim lngLen As Long
Dim VarItem As Variant
Dim i As Integer
Const conJetDate = "\#mm\/dd\/yyyy\#"
If Not IsNull(Me.lstWaterbody) Then
StrWhere = StrWhere & "[waterbody_id] = " & Me.lstWaterbody & " AND "
End If
If Not IsNull(Me.txtStartDate) Then
StrWhere = StrWhere & "[sampling_date] >= " &
Format(Me.txtStartDate, conJetDate) & " AND "
End If
If Not IsNull(Me.txtEndDate) Then
StrWhere = StrWhere & "[sampling_date] <= " & Format(Me.txtEndDate,
conJetDate) & " AND "
End If
If Me.chkSurface = True Then
StrWhere = StrWhere & "[depth_round] = " & 0 & " AND "
End If
StrWhere = StrWhere & "([station_id] IN("
For i = 0 To Me.lstStationID.ListCount - 1
If Me.lstStationID.Selected(i) Then
StrWhere = StrWhere & "'" & Me.lstStationID.Column(0, i) & "',"
End If
Next i
StrWhere = Left(StrWhere, Len(StrWhere) - 2) & "'))"
Debug.Print StrWhere
Me.Filter = StrWhere
Me.FilterOn = True
End Sub
event. It works great as long as the user selects one or more items in the
multi-select list box [lstStationID]. If nothing is selected, the where
string has unneccsary characters on the end of it. So, I think I could do one
of two things: 1) If nothing is selected, have code that chops off more
characters at the end of the where string or 2) require the user to select
one or more items and have a message box appear if the user clicks the search
button without selecting anything. However, I am having trouble getting
either of these methods to work. Does anyone have any suggestions on how to
handle this?
Thank you!
Private Sub cmdInSituFilter_Click()
Dim StrWhere As String
Dim lngLen As Long
Dim VarItem As Variant
Dim i As Integer
Const conJetDate = "\#mm\/dd\/yyyy\#"
If Not IsNull(Me.lstWaterbody) Then
StrWhere = StrWhere & "[waterbody_id] = " & Me.lstWaterbody & " AND "
End If
If Not IsNull(Me.txtStartDate) Then
StrWhere = StrWhere & "[sampling_date] >= " &
Format(Me.txtStartDate, conJetDate) & " AND "
End If
If Not IsNull(Me.txtEndDate) Then
StrWhere = StrWhere & "[sampling_date] <= " & Format(Me.txtEndDate,
conJetDate) & " AND "
End If
If Me.chkSurface = True Then
StrWhere = StrWhere & "[depth_round] = " & 0 & " AND "
End If
StrWhere = StrWhere & "([station_id] IN("
For i = 0 To Me.lstStationID.ListCount - 1
If Me.lstStationID.Selected(i) Then
StrWhere = StrWhere & "'" & Me.lstStationID.Column(0, i) & "',"
End If
Next i
StrWhere = Left(StrWhere, Len(StrWhere) - 2) & "'))"
Debug.Print StrWhere
Me.Filter = StrWhere
Me.FilterOn = True
End Sub