Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing a form using a variable name.

Status
Not open for further replies.

rainsworth

Programmer
Feb 12, 2002
6
GB
Trying to set focus to a form using a variable. Here is the code. - Thanks

Set dbs = CurrentDb
Set RST = dbs.OpenRecordset("Functions")
Function_name = Trim(Forms!Main_menu.FunctionsCMB.Value)
Form_Name = Trim(RST.Fields!form_alias.Value)

RST.MoveFirst
Do While Not RST.EOF
If Function_name = Trim(RST.Fields![User/Manage_Functions].Value) Then
DoCmd.OpenForm (Form_Name) ' This works !
Forms!Main_menu.SetFocus
DoCmd.Close
Forms!(Form_Name).SetFocus ' This does not work
RST.MoveLast
RST.MoveNext
Else
RST.MoveNext
End If
Loop
End Sub
 
Simple syntax problem. Change the line:

Forms!(Form_Name).SetFocus ' This does not work

to

Forms(Form_Name).SetFocus ' This will now work

ie. remove the ! character; you only use it if you're hardcoding the form name.



Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top