Avatar of ChadLittle
ChadLittle

asked on 

Calling afterupdate events with variables

I have a public function in a public module that is working with many forms.  I have everything working except lines 6 and 23 where I am trying to set a variable and then use that variable to call the afterupdate event of the form control represented by the variable.  Could you give me alternate versions of these lines that would work?
Public Sub CreateOrderLines(frm As Form, strFormName As String, strSubformName As String)

Dim rsSourceLines As Recordset
Dim strAfterUpdate As String

strAfterUpdate = ("cboSOLinesID_AfterUpdate") 'even better would be strAfterUpdate = (strControlName & "_AfterUpdate")

    Set rsSourceLines = CurrentDb.OpenRecordset("SELECT " & strTableName & "." & strFieldName & ", " & strTableName & ".UnitsID, " & strTableName & "." & strSelectField & ", " & strTableName & ".WarehouseID, tblSOHeader.PVID, tblSOHeader.dtmDate, tblItems.VendorsID " _
                    & "FROM tblItems INNER JOIN (tblSOHeader INNER JOIN " & strTableName & " ON tblSOHeader.SOHeaderID = " & strTableName & ".SOHeaderID) ON tblItems.ItemsID = " & strTableName & ".ItemsID " _
                    & "WHERE (((" & strTableName & "." & strSelectField & ") > 0) And  ((tblSOHeader.SOHeaderID) = " & frm![txtSOHeaderID] & strCreateOrderLinesWhere & varVendorWhere & ")) " _
                    & "ORDER BY " & strTableName & "." & strFieldName & "; ")
                    
DoCmd.OpenForm strFormName
DoCmd.GoToRecord acDataForm, strFormName, acLast
    
With Forms(strFormName).Controls(strSubformName).Form

    Do Until rsSourceLines.EOF
            .Recordset.AddNew
            .Controls(strControlName) = rsSourceLines(strFieldName)
            .lngUnitQuantity = rsSourceLines(strSelectField)
            .UnitsID = rsSourceLines!UnitsID
            .(strAfterUpdate) 'This would work if I typed cboSOLinesID_AfterUpdate, but how do I make it work with a variable?
            .Dirty = False
            rsSourceLines.MoveNext
    Loop
    
End With

End Sub

Open in new window

Thank you.
Chad
Microsoft Access

Avatar of undefined
Last Comment
Gustav Brock

8/22/2022 - Mon