C
C
Hello,
I have three for combo boxes that I would like to use to limit the results
on a form. I am having trouble geeting them to work together. I listed my
code below and I think my problem is with the last section:
Form_frmRMISGeneral.RecordSource = LSQL3.
I have three different code examples listed below for reference:
Thank you for your help in advance.
1) Two are used to caputure the Start and End Date form a calendar control
(LSQL & LSQL1)
2) LSQL2 is for the Ship Category
3) LSQL3 is for the the type of Ship in the Ship Category. I set the after
update to goto Sub Set Filter:
Private Sub cboShipTypeHull_AfterUpdate()
'Call subroutine to set filter based on selected Ship Class
SetFilter
End Sub
Sub SetFilter()
Dim LSQL As String
Dim LSQL1 As String
Dim LSQL2 As String
Dim LSQL3 As String
LSQL = "select * from qryMTTC"
LSQL1 = "select * from qryMTTC"
LSQL2 = "select * from qryMTTC"
LSQL3 = "select * from qryMTTC"
LSQL = LSQL & " where date_maintenance_action = '" & cboStartDate & "'"
LSQL1 = LSQL1 & " where date_maintenance_action = '" & cboEndDate & "'"
LSQL2 = LSQL2 & " where ship_class = '" & cboShipClass & "'"
LSQL3 = LSQL3 & " where ship_type_hull = '" & cboShipTypeHull & "'"
' Form_frmRMISGeneral.RecordSource = LSQL
' Form_frmRMISGeneral.RecordSource = LSQL1
' Form_frmRMISGeneral.RecordSource = LSQL2
Form_frmRMISGeneral.RecordSource = LSQL3
End Sub
I modified the following code but nothing happens:
Sub SetFilter()
Dim strShipClass As String
Dim strShipTypeHull As String
Dim StrStartDate As String
Dim strEndDate As String
Dim strFilter As String
' Check that the report is open
If SysCmd(acSysCmdGetObjectState, acForm, "frmRMISSplash") <>
acObjStateOpen Then
MsgBox "You must open the report first."
Exit Sub
End If
' Build criteria string for StartDate field
If IsNull(Me.cboStartDate.Value) Then
StrStartDate = "Like '*'"
Else
StrStartDate = "='" & Me.cboStartDate.Value & "'"
End If
' Build criteria string for EndDate field
If IsNull(Me.cboEndDate.Value) Then
strEndDate = "Like '*'"
Else
strEndDate = "='" & Me.cboEndDate.Value & "'"
End If
' Build criteria string for ShipClass field
If IsNull(Me.cboShipClass.Value) Then
strShipClass = "Like '*'"
Else
strShipClass = "='" & Me.cboShipClass.Value & "'"
End If
' Combine criteria strings into a WHERE clause for the filter
strFilter = "[date_maintenance_action] " & StrStartDate & " AND
[date_maintenance_action] " & strEndDate & " AND [ship_class] " & "
strShipClass & " AND [ship_type_hull] " & strShipTypeHull
' Apply the filter and switch it on
With Forms![frmRMISSplash]
.Filter = strFilter
.FilterOn = True
End With
Code Example 3:
'Dim strWhere As String
'Dim StrStartDate As String
'Dim strEndDate As String
'Dim strShipClass As String
'Dim strShipTypeHull As String
'StrStartDate = "#" & Format(Me.cboStartDate.Value, "mm/dd/yyyy") & "#"
'strEndDate = "#" & Format(Me.cboEndDate.Value, "mm/dd/yyyy") & "#"
'strShipClass = Me.cboShipClass.Value
'strShipTypeHull = Me.cboShipTypeHull.Value
'strWhere = "SELECT qry.MTTC.* " & _
'"FROM qry.MTTC " & _
'"WHERE tbl.Maintenance.date_maintenance_action = "
"when_discovered_date between" & StrStartDate & " and " & strEndDate'" & _
'"AND tbl.Maintenance.ship_class" & strShipClass & _
'"AND tbl.Maintenance.ship_type_hull" & strShipTypeHull & _
'"ORDER BY tbl.Maintenance.ship_class,tbl.Maintenance.ship_type_hull;"
I have three for combo boxes that I would like to use to limit the results
on a form. I am having trouble geeting them to work together. I listed my
code below and I think my problem is with the last section:
Form_frmRMISGeneral.RecordSource = LSQL3.
I have three different code examples listed below for reference:
Thank you for your help in advance.
1) Two are used to caputure the Start and End Date form a calendar control
(LSQL & LSQL1)
2) LSQL2 is for the Ship Category
3) LSQL3 is for the the type of Ship in the Ship Category. I set the after
update to goto Sub Set Filter:
Private Sub cboShipTypeHull_AfterUpdate()
'Call subroutine to set filter based on selected Ship Class
SetFilter
End Sub
Sub SetFilter()
Dim LSQL As String
Dim LSQL1 As String
Dim LSQL2 As String
Dim LSQL3 As String
LSQL = "select * from qryMTTC"
LSQL1 = "select * from qryMTTC"
LSQL2 = "select * from qryMTTC"
LSQL3 = "select * from qryMTTC"
LSQL = LSQL & " where date_maintenance_action = '" & cboStartDate & "'"
LSQL1 = LSQL1 & " where date_maintenance_action = '" & cboEndDate & "'"
LSQL2 = LSQL2 & " where ship_class = '" & cboShipClass & "'"
LSQL3 = LSQL3 & " where ship_type_hull = '" & cboShipTypeHull & "'"
' Form_frmRMISGeneral.RecordSource = LSQL
' Form_frmRMISGeneral.RecordSource = LSQL1
' Form_frmRMISGeneral.RecordSource = LSQL2
Form_frmRMISGeneral.RecordSource = LSQL3
End Sub
I modified the following code but nothing happens:
Sub SetFilter()
Dim strShipClass As String
Dim strShipTypeHull As String
Dim StrStartDate As String
Dim strEndDate As String
Dim strFilter As String
' Check that the report is open
If SysCmd(acSysCmdGetObjectState, acForm, "frmRMISSplash") <>
acObjStateOpen Then
MsgBox "You must open the report first."
Exit Sub
End If
' Build criteria string for StartDate field
If IsNull(Me.cboStartDate.Value) Then
StrStartDate = "Like '*'"
Else
StrStartDate = "='" & Me.cboStartDate.Value & "'"
End If
' Build criteria string for EndDate field
If IsNull(Me.cboEndDate.Value) Then
strEndDate = "Like '*'"
Else
strEndDate = "='" & Me.cboEndDate.Value & "'"
End If
' Build criteria string for ShipClass field
If IsNull(Me.cboShipClass.Value) Then
strShipClass = "Like '*'"
Else
strShipClass = "='" & Me.cboShipClass.Value & "'"
End If
' Combine criteria strings into a WHERE clause for the filter
strFilter = "[date_maintenance_action] " & StrStartDate & " AND
[date_maintenance_action] " & strEndDate & " AND [ship_class] " & "
strShipClass & " AND [ship_type_hull] " & strShipTypeHull
' Apply the filter and switch it on
With Forms![frmRMISSplash]
.Filter = strFilter
.FilterOn = True
End With
Code Example 3:
'Dim strWhere As String
'Dim StrStartDate As String
'Dim strEndDate As String
'Dim strShipClass As String
'Dim strShipTypeHull As String
'StrStartDate = "#" & Format(Me.cboStartDate.Value, "mm/dd/yyyy") & "#"
'strEndDate = "#" & Format(Me.cboEndDate.Value, "mm/dd/yyyy") & "#"
'strShipClass = Me.cboShipClass.Value
'strShipTypeHull = Me.cboShipTypeHull.Value
'strWhere = "SELECT qry.MTTC.* " & _
'"FROM qry.MTTC " & _
'"WHERE tbl.Maintenance.date_maintenance_action = "
"when_discovered_date between" & StrStartDate & " and " & strEndDate'" & _
'"AND tbl.Maintenance.ship_class" & strShipClass & _
'"AND tbl.Maintenance.ship_type_hull" & strShipTypeHull & _
'"ORDER BY tbl.Maintenance.ship_class,tbl.Maintenance.ship_type_hull;"