VBA Go To Specific Control After Update

Damo1412

Registered User.
Local time
Yesterday, 23:19
Joined
Nov 15, 2010
Messages
65
Hi,

I would like to move to a specific tab stop location after update if the current field is left bank.

I have tried using the code:
Code:
Private Sub JobDueBy_AfterUpdate()

if Me.JobDueBy = "" then
DoCmd.GoToControl Me.JobsLive
Me.Refresh

End Sub
But if the user presses "Tab" or "Enter" the cursor goes to the next tab stop instead
 
is the code actually running? because the code won't work - missing an end if

also since no change is made, the afterupdate won't be triggered, so you'll need a different event. perhaps lostfocus or exit

otherwise, perhaps the control is null so try

if nz(JobDueBy,"")="" then....

another thing to try is setfocus rather than gotocontrol
 
Sorry, I missed the End If over when I copied the code. It's actually part of a nested If...Else but only copied the relevant section over.

I'll have a look in to lostfocus and setfocus and have a play around with them.

Thanks
 
one other thought, JobDueBy sounds like it is a date field which is stored as a number. If so then better to use

if nz(JobDueBy,0)=0 then....
 
Hi CJ_London,

You're right in saying that JobDueBy is a date however I chose this field at random out of all of the fields I would like to use this function on. These fields include reference numbers, text and check boxes.
 
ok, well make sure you use the correct context depending on field type
 

Users who are viewing this thread

Back
Top Bottom