How to refer a control from a module...

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

In the module, I have the control name from a form stored as a global
variable. I need to refer that control in the module and it will not allow
part of the path like the control name expressed as a variable.

Option Compare Database
Option Explicit

Sub ChangeControl()
Dim strFieldName As String

strFieldName = Old.FieldName 'Control name in a form stored as a global
variable

Forms![Form1]!strFieldName.Undo
Forms![Form1]!strFieldName = Old.strOldValue
DoCmd.Close
End sub
 
Paul said:
In the module, I have the control name from a form stored as a global
variable. I need to refer that control in the module and it will not
allow part of the path like the control name expressed as a variable.

Option Compare Database
Option Explicit

Sub ChangeControl()
Dim strFieldName As String

strFieldName = Old.FieldName 'Control name in a form stored as a
global variable

Forms![Form1]!strFieldName.Undo
Forms![Form1]!strFieldName = Old.strOldValue
DoCmd.Close
End sub

With Forms!Form1.Controls(strFieldName)
.Undo
.Value = Old.strOldValue
End With
 
Back
Top