troubleshooting Question

Calling afterupdate events with variables

Avatar of ChadLittle
ChadLittle asked on
Microsoft Access
24 Comments4 Solutions815 ViewsLast Modified:
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
Thank you.
Chad
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 4 Answers and 24 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 4 Answers and 24 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros