Reference a control dynamically

G

Guest

I have a private sub based on an ‘OnDirty’ event. The event creates a record
in an audit log. Here is the code:

Private Sub cmbBusClass_Dirty(Cancel As Integer)
userID = fOSUserName()
FormUsed = Me.Name
ChangeDesc = "Changed Business Class"
RecordNum = Me.RecordID

OrigVal = Me.cmbBusClass

strSQL = "INSERT INTO
tAuditLog(txtNTName,lngRecordID,txtChange,txtForm,dtmDate,dtmTime,txtOrigVal)
" & _
"VALUES ('" & userID & "','" & RecordNum & "','" & ChangeDesc & "','" &
FormUsed & "','" & Date & "','" & Time & "','" & OrigVal & "')"


DoCmd.RunSQL strSQL
End Sub

I want to declare OrigVal as the name of the control, without using the
control name. This type of sub will run on ten different forms, along with
OnError events that will append a 0 if the OrigVal is null.

Is there a way to do this?

Thanks in advance!
PJ
 
G

Guest

Try the following statement:

OrigVal = Me.activecontrol.name

This should capture the name of the currently active contol.
 
G

George Nicholson

OrigVal = Screen.ActiveControl.Name

As written, that would store the name of the control in your AuditLog, but I
see no provision to store the value of that control (which would be
Me.Controls(OrigVal).Value or just Screen.ActiveControl.Value)

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top