I'm working with Access 2000. I have a form with data from a table, tblParts, and a list box with data from another table, tblRDM_Numbers. The two tables have a one-many relationship with tblParts.name as a foreign key for tblRDM_Numbers. I would like the list box to update every time the Form's record moves. The sub I wrote looks like this:
Public Sub populateRDM() Dim strSQL As String Dim strPart As String strPart = Me.Recordset.Fields("name").Value strSQL = "SELECT tblRDM_Numbers.part, tblRDM_Numbers.RDM_No " _ & "FROM tblRDM_Numbers " _ & "WHERE tblRDM_Numbers.part = '" & strPart & "';" Me!lstRDM.RowSource = strSQL End Sub
It works fine when I call it almost anywhere except Form_Current(). When Form_Current() calls populateRDM(), it strPart is assigned Me.RecordSet.Fields("name").Value before the record changes. Then, the record changes, and the list box contains information for the record before the change.
For example, I have three parts, Battery, Capacitor, and Resistor. I load the form, and Battery's information is displayed. The RDM numbers in the list box are those for battery. Then I move to the next record. The information for Capacitor is displayed, but the list box contains Battery's RDM numbers. I move to the next record, Resistor, but Capacitor's RDM numbers are displayed. I move back to Capacitor, but Resistor's RDM numbers are shown in the list. Etc.
Is there a way to call populateRDM() after the record moves, instead of before? It would be lovely if VBA had BeforeCurrent and AfterCurrent events, but I'll work with what I've got.