I’m still having a problem with using a combo box in a main form to select records to be displayed in a subform. I’ve tried code suggested in several sources, but it doesn’t work.
In “Filter records based on a combo box selection in Access 2004/XP/2000/97,” Microsoft provides an example of a database that has two forms: frmCustomers (main form) and frmCustomers_su b (subform). Microsoft suggests this code for a main form to set a filter for a subform’s recordset:
The example works. However, it doesn’t work when I attempt to use similar code in my application. The problem in my application occurs in the fourth line of the code that appears to refer to a form named Form_frmCustome rs_sub. There’s no form with that name in Microsoft’s database. I assume this way of referring to a subform is a special syntax for subforms. However, I cannot find any explanation of this format in Access Help, in on-line sources, or in any of the Access books I have.
By setting a breakpoint in the code, I’ve tried several ways to access a subform’s properties in the Immediate window. When I use:
I get the error message ‘Run-time error 424. Object required.’
The format that works to access the RecordSource property of a subform named Book Subform is:
After setting the property in the Immediate window, I can query the property (also in the Immediate window) to confirm that it has been correctly set. After incorporating the same format in the VBA code, and making a selection in the combo box on the main form, I still don’t see the correct records displayed in the subform, even after I requery the subform.
I’ll appreciate any help in these matters.
Gordon Padwick
In “Filter records based on a combo box selection in Access 2004/XP/2000/97,” Microsoft provides an example of a database that has two forms: frmCustomers (main form) and frmCustomers_su b (subform). Microsoft suggests this code for a main form to set a filter for a subform’s recordset:
Code:
Dim LSQL As String LSQL = “select * from Customers” LSQL = LSQL & “ where CustomerID = ‘” & cboSelected & “’” Form_frmCustomers-sub.RecordSource = LSQL
By setting a breakpoint in the code, I’ve tried several ways to access a subform’s properties in the Immediate window. When I use:
Form_Book_Subfo rm.RecordSourceI get the error message ‘Run-time error 424. Object required.’
The format that works to access the RecordSource property of a subform named Book Subform is:
Me.Book_Subform .Form.RecordSou rceAfter setting the property in the Immediate window, I can query the property (also in the Immediate window) to confirm that it has been correctly set. After incorporating the same format in the VBA code, and making a selection in the combo box on the main form, I still don’t see the correct records displayed in the subform, even after I requery the subform.
I’ll appreciate any help in these matters.
Gordon Padwick
Comment