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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use the contents of a memvar to set focus?

Status
Not open for further replies.

steve728

Programmer
Mar 16, 2003
536
US
How do I accomplish the following?
If Trim(mARMasterScreen) <> "" Then
mScreen = "Forms![" & mARMasterScreen & "].SetFocus"
Eval (mScreen)
' The contents of the memvar = Forms!["Sales"].SetFocus
Else
Forms![Main Tabs]![AR Customer Listing].SetFocus
End If

I just want to set the focus to Forms![Sales]. What am I doing wrong?

Steve G.
 
If I understand correctly mARMasterScreen evaluates to "Sales". If that is the case, simply:

if not Trim(mARMasterScreen & " ") = "" Then
Forms.(mARMasterScreen).SetFocus"
Else
 
I appreciate the quick reply but the advise doesn't help. It's my fault for not being more explicit.

I want to replace all of the following:
Case 7 ' General Ledger tab
If Trim(mGLMasterScreen) <> "" Then
If Trim(mGLMasterScreen) = "Chart of Accounts" Then
Forms![Chart of Accounts].SetFocus
ElseIf Trim(mGLMasterScreen) = "Accounts" Then
Forms![Accounts].SetFocus
ElseIf Trim(mGLMasterScreen) = "View Entries" Then
Forms![View Entries].SetFocus
ElseIf Trim(mGLMasterScreen) = "GJ Profile" Then
Forms![GJ Profile].SetFocus
ElseIf Trim(mGLMasterScreen) = "GLWorkAR1" Then
Forms![GLWorkAR1].SetFocus
ElseIf Trim(mGLMasterScreen) = "GLWorkAR2" Then
Forms![GLWorkAR2].SetFocus
ElseIf Trim(mGLMasterScreen) = "GLWorkAP1" Then
Forms![GLWorkAp1].SetFocus
Else
Forms![Main Tabs]![General Ledger Menu].SetFocus
End If
Else
Forms![Main Tabs]![General Ledger Menu].SetFocus
End If

with the following:

If Trim(mGLMasterScreen) <> "" Then
mScreen = "Forms![" & mGLMasterScreen & "].SetFocus"
Eval (mScreen)
Else
Forms![Main Tabs]![General Ledger Menu].SetFocus
End If
 
No, I think I did understand.

If I use the Dot notation instead of the Bang notation I can use a variable

So
if not Trim(mARMasterScreen & " ") = "" Then
Forms.(mARMasterScreen).SetFocus
Else

If mArMasterScreen evaluates to "Chart of Accounts" then it definately will set the focus to

Forms("Chart of Accounts")

Isn't that what you want?
 
Thank you so much! You deserve a star!

Steve
 
I am a anti Bang notation person, while other really like it. It is open to debate. However, you can do this in Dot.

Dim strFormName as string
strFormName = "Form Name"

By variable
Forms(strFormName).setFocus

By named index
Forms("Form Name").setFocus

or by its integer index in the collection
Forms(0).setfocus

I will look at your other post, but I did not understand it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top