Control.setFocus vs GotoControl Issue

FuzMic

DataBase Tinker
Local time
Today, 18:52
Joined
Sep 13, 2006
Messages
744
Hi forum mates

This thread aims to share a sticky issue relating to the use of Docmd.GotoControl within a BeforeUpdate event script for a form. The Access in use is 2003 SP2 or 2002 SP3.

2 errors occur when a script runs into GotoCtrl statement during the beginning of an execution of a form
1 There is no field named FldName in the current record (2109)
2 The command or action "GotoControl" isn't available now (2046)

These errors will disappear after the script had handle the errors once.

To go around this problem, I replace the GotoCtrl statement with Control.setFocus.

Question:
Is there some constraint in the use of GotoC.. or why Ctrl.SetF.. works perfectly.

Views appreciate to understand what's happening. :)
 
Last edited:
You haven't provided any detail of your commands so it is a bit difficult to analyse the problem. However I suspect the syntax of your GotoCtrl command is incorrect and the variation in behaviour is about the current focus.

There is a small only a very small difference between referring to a field in the current record of the form's Record Source and a control on the form as Me......
 
Thanks mate
The command within the BeforeUpdate Event is

if isnull(CtrlName) then
Docmd.gotoControl "CtrlName"
end if

How's that?
 
eh?

if isnull(CtrlName) then
Docmd.gotoControl "CtrlName"
end if

looks realy odd

if a variable called ctrlname is null (which only a variant could be) then goto a control named "ctrlname" which is unlikely to exist.
 
Ditto what Dave with the Husky said. But I assume this is just how you expressed it here.

2 errors occur when a script runs into GotoCtrl statement during the beginning of an execution of a form
1 There is no field named FldName in the current record (2109)
2 The command or action "GotoControl" isn't available now (2046)

Error 1: Sounds like the focus is in either a parent or subform and it can't find the fieldname you are expecting.

Error 2: Can't find the control for the same reason.

Later when the focus is where you expect no error is produced.

The difference I was thinking of is to do with Me!somename vs Me.somename vs Me.form!somename which can get confused between controls and fields. This may be why the focus is not where you expect.
 
Both of u open up some ideas, will come back after some tinkering. Thanks.
 

Users who are viewing this thread

Back
Top Bottom