Setting a forms focus using a variable (1 Viewer)

gblack

Registered User.
Local time
Today, 16:10
Joined
Sep 18, 2002
Messages
632
I have two (or more) forms open. I want to set a form (that doesn't have focus) as the active form. I think I do this like so:

Forms!FormName.SetFocus

But I am using a variable to denote the form I want to be Active.

lets say the varibale name is frm12bActive.

So if I wrote this variable in the code:
Forms!frm12bActive.SetFocus

Wouldn't Access be looking for a form Named frm12bActive?

How do I reference the form I want to be active using the varible.

I am not even sure the initial code is correct, but I did get it off of another thread on this forum... so i think it's probably correct...

Thanks,
Gary
 

gblack

Registered User.
Local time
Today, 16:10
Joined
Sep 18, 2002
Messages
632
Never mind.. I just found it... I just replace the bang with parens

Forms(frm12bActive).setfocus
 

boblarson

Smeghead
Local time
Today, 08:10
Joined
Jan 12, 2001
Messages
32,059
And just an extra little tidbit for you. If you want to refer to a control on the form with a variable as well you can do this:

Forms(variableNameHere).Controls(controlVariableNameHere).Value = "whatever"

If you use this method, you have to provide the .Value because all controls don't have a value property so it can't be the default like it can be if you use the direct name.
 

jwdesselle

New member
Local time
Today, 10:10
Joined
Oct 22, 2007
Messages
1
gblack and boblarson, YOU TWO ROCK!!!! I've been scratching my head for a week trying to figure out how to incorporate a variable in a reference like this. (parentheses saves lives)

John - Baton Rouge, LA
 

Users who are viewing this thread

Top Bottom