Using variables in controls

Neal

Registered User.
Local time
Today, 10:14
Joined
Feb 17, 2000
Messages
116
I need to use a variable to set the focus on one of a dozen fields.
I have a user input form with a textbox (txtField) on it where the number of the field (the field names are all numbers) is entered. The code behind the after update event of txtField is:

Dim intField as Integer
Dim strFieldName as Control

intField = me.txtField
strFieldName = "forms!frmEntry![" & intfield & "]"

strFieldName.SetFocus

When I run this, I get error 91: object variable or with block variable not set.

When I put Set in front of the line setting the value of strFieldName, I get type mismatch
When I change the intField to Variant instead of Integer, I get Runtime error 424, Object required.

Anybody know what I need to do to make this work?
 
Instead of:

Dim intField as Integer
Dim strFieldName as control
intField = me.txtField
strFieldName = "forms!frmEntry![" & intfield & "]"

strFieldName.SetFocus

try

Dim strFieldName as string
strFieldName = "[" & Me.TxtField & "]"

If the control is on the same form use

Me(strFieldName).SetFocus
or if on a different form use:
Form_frmEntry(strFieldName).setfocus

Should work fine.

Ian
 
Fornatian,

You're great! I was about to pull my hair out, and none of our office VBA experts were able to help.

Thanks,
Neal
 
No doubt!
smile.gif
 

Users who are viewing this thread

Back
Top Bottom