Reference a control dynamically

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
Try the following statement:

OrigVal = Me.activecontrol.name

This should capture the name of the currently active contol.
 
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,
 
Back
Top