I wonder whether any guidance can be offered up re the following, please.
I have a tab control set within a main form, and on the one tab that I've created so far (to introduce others later), I have a subform.
Also on the main form (within the Form Header), I have a couple so far (to introduce others later) of Option Buttons, named optTC and optIP. Not an Option Group, mind you; Option Buttons that are independent of each other. So it could be that : neither are ticked; one or other is ticked; or both are ticked. I want to use those Option Buttons to filter the records in the subform (which has a 'continuous' layout).
The main form and subform are linked (unbound date selector on main form, and a 'PlannedStartDate' field on the subform).
The VBA on the After Update Event for the option buttons is currently as follows :
And the VBA for the called 'FilterSubform' is :
There are no criteria at all within the source Query for the subform. The Query just brings together various fields from various Tables. Included amongst the fields is a Status field. (TC and IP are the two possible options for Status). I'm trying to filter the subform according to what Option Buttons are and are not ticked, but can't get it to work.
Can anyone tell me where I'm going wrong, please ?
I have a tab control set within a main form, and on the one tab that I've created so far (to introduce others later), I have a subform.
Also on the main form (within the Form Header), I have a couple so far (to introduce others later) of Option Buttons, named optTC and optIP. Not an Option Group, mind you; Option Buttons that are independent of each other. So it could be that : neither are ticked; one or other is ticked; or both are ticked. I want to use those Option Buttons to filter the records in the subform (which has a 'continuous' layout).
The main form and subform are linked (unbound date selector on main form, and a 'PlannedStartDate' field on the subform).
The VBA on the After Update Event for the option buttons is currently as follows :
Code:
Private Sub optTC_AfterUpdate()
FilterSubform
End Sub
Private Sub optIP_AfterUpdate()
FilterSubform
End Sub
And the VBA for the called 'FilterSubform' is :
Code:
Private Sub FilterSubform()
Dim strSQLSourceQuery As String
Dim strSQLWhere As String
Dim strSQL As String
Dim strJoin As String
Select Case Me.TabCtrl1.Value
'BlockingAndSequencing tab'
Case Me.pageBlockingAndSequencing.PageIndex
strSubformName = "sfrmDay_BlockingAndSequencing"
strSQLSourceQuery = "SELECT * FROM qry_sfrmDay_BlockingAndSequencing "
'Other tabs to be introduced later
End Select
strJoin = "OR"
strSQLWhere = ""
'optTC
If optTC = -1 Then 'TC is ticked
strSQLWhere = "WHERE"
strSQLWhere = strSQLWhere & " [AOStatus] = 'TC' "
End If
'optIP
If optIP = -1 Then
If Len(strSQLWhere) = 0 Then 'TC is not ticked
strSQLWhere = "WHERE"
strSQLWhere = strSQLWhere & " [AOStatus] = 'IP' "
Else 'TC & IP are both ticked
strSQLWhere = strSQLWhere & strJoin & " [AOStatus] = 'IP' "
End If
End If
strSQL = strSQLSourceQuery & strSQLWhere
Me.objSubform.Form.RecordSource = strSQL
Me.objSubform.LinkMasterFields = "unboundDateSelector"
Me.objSubform.LinkChildFields = "PlannedStartDate"
Me.objSubform.SourceObject = strSubformName
Me.objSubform.Top = Me.lblAnchor.Top
Me.objSubform.Left = Me.lblAnchor.Left
Me.objSubform.Visible = True
[Forms]![frmDayToDay]![objSubform].Requery
End Sub
There are no criteria at all within the source Query for the subform. The Query just brings together various fields from various Tables. Included amongst the fields is a Status field. (TC and IP are the two possible options for Status). I'm trying to filter the subform according to what Option Buttons are and are not ticked, but can't get it to work.
Can anyone tell me where I'm going wrong, please ?