Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Calling afterupdate events with variables

Avatar of ChadLittle
ChadLittle asked on
Microsoft Access
24 Comments1 Solution815 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
            .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
End With

End Sub
Thank you.