Using variable for Form name? (1 Viewer)

lana

Registered User.
Local time
Today, 05:58
Joined
Feb 10, 2010
Messages
92
Dear All,

Is there a way to use a variable instead of a form name?

e.g. FRM1 is a form

Forms![FRM1]!textbox1.SetFocus

Instead of FRM1 , a variable is used which can be any other form name.??????

Cheers
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 18:28
Joined
Aug 30, 2003
Messages
36,118
Try

Forms(VariableName).TextboxName
 

lana

Registered User.
Local time
Today, 05:58
Joined
Feb 10, 2010
Messages
92
Thanks very much.

Is there a way to use variable for the controls too?

like this :
Forma(fff).Textbox1.setfocus
Instead of Textbox1 we use a variable ??

Cheers
 

Mile-O

Back once again...
Local time
Today, 01:28
Joined
Dec 10, 2002
Messages
11,316
Forms(varName).Controls(varOtherName)
 

Simon_MT

Registered User.
Local time
Today, 01:28
Joined
Feb 26, 2007
Messages
2,177
Or:

Code:
    With CodeContextObject
        If .[Orig Location].TabStop = True Then
            .[Orig Location].TabStop = False
            .[Orig Stocktake].TabStop = True
            DoCmd.GoToControl "Orig Stocktake"
        End If
    End With
Simon
 
Last edited:

lana

Registered User.
Local time
Today, 05:58
Joined
Feb 10, 2010
Messages
92
Thanks Simon,

May be this a simple question but can you tell me where this code is used?

Cheers
LANA
 

Simon_MT

Registered User.
Local time
Today, 01:28
Joined
Feb 26, 2007
Messages
2,177
In a Module here is the full module:

Code:
Function LocationsOriginals_Change()

    With CodeContextObject
        If .[Orig Location].TabStop = True Then
            .[Orig Location].TabStop = False
            .[Orig Stocktake].TabStop = True
            DoCmd.GoToControl "Orig Stocktake"
            Exit Function
        End If

        If .[Orig Stocktake].TabStop = True Then
            .[Orig Stocktake].TabStop = False
            .[Orig Status].TabStop = True
            DoCmd.GoToControl "Orig Status"
            Exit Function
        End If

        If .[Orig Status].TabStop = True Then
            .[Orig Status].TabStop = False
            .[Orig Location].TabStop = True
            DoCmd.GoToControl "Orig Location"
        End If
    End With
End Function

This is then called on a form Event as =LocationsOriginals_Change()

Simon
 

lana

Registered User.
Local time
Today, 05:58
Joined
Feb 10, 2010
Messages
92
Sorry , but are Orig Stocktake , orig Status , orig Location fields?
 

Simon_MT

Registered User.
Local time
Today, 01:28
Joined
Feb 26, 2007
Messages
2,177
Sorry, I should have been more speciifc and yes and can relate to any Form that they are a control.

Simon
 

lana

Registered User.
Local time
Today, 05:58
Joined
Feb 10, 2010
Messages
92
Thanks.

I still don't get it !!! but I will try to see what happens!?

Cheers
 

Users who are viewing this thread

Top Bottom