How to refer a control from a module...

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
 
D

Dirk Goldgar

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
 

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