I have a list box that controls the display of information on a form and its subform.
I am having problems with the code to change Child/Parent links according to what is selected in the list box and a combo box (both on the main form):
I want:
-the subform to display only the records corresponding to a specific work order when a given order is selected in the list box
-the subform to display all records if "All work orders" is selected
-the subform to display all records for a given month when "All work orders and a month is selected
The code is the AfterUpdate event of the Listbox.
Expand|Select|Wrap|Line Numbers
- Private Sub SubFormLinkRules()
- 'Decides and sets how subform is linked to Main form
- Dim strChild As String
- Dim strMaster As String
- If Me.Liste21.ListIndex = 0 Then
- '0 corresponds to <All work orders> in the listbox
- If Me.cmbMois = "<All months>" Then ' Me.cmbMonth is field in the Main form
- strMaster = vbNullString
- strChild = vbNullString
- Else
- strMaster = "[cmbMonth]"
- strChild = "[Month]" 'Month is a field on the subform
- End If
- Else
- strMaster = "[CodeCmd]" 'CodeCmd is a field on the main form and subform
- strChild = "[CodeCmd]"
- End If
- Me.frmCmdComm.LinkMasterFields = strMaster 'frmCmdComm is the subform
- Me.frmCmdComm.LinkChildFields = strChild
- ' After having selected <All work orders> in the list box
- ' and a value in cmbMonth if I try to select
- ' something further down the listbox I get an error.
- ' I think it is because strMaster isn't changing. But why?
- End Sub
Thank you in advance for your insight.