set focus to next record after before update

  • Thread starter Thread starter JHSJ
  • Start date Start date
J

JHSJ

Guest
I want to set the focus to the top control of the next record if the user clicks OK to the following message box:

Private Sub Form_BeforeUpdate(Cancel As Integer)
'Check to determine if the user knows the date is outside the range 1999-2001

Dim strMessage As String
Dim intOptions As Integer
Dim bytChoice As Byte

If Arrival_Dt < #1/1/99# Or Arrival_Dt > #12/31/01# Or IsNull(Arrival_Dt) Then
strMessage = "Year should be 1999, 2000 or 2001 for Arrival Date." & _
Chr(13) & "Save anyway?"
intOptions = vbQuestion + vbOKCancel
bytChoice = MsgBox(strMessage, intOptions)

If bytChoice = vbCancel Then
Arrival_Dt.SetFocus
Cancel = True
End If
End If
End Sub

When I click the move next record control and get the message box above, and then click OK, the focus goes to the Arrival_Dt control instead of the first field of the next record. I think it would be more intuitve for the user if the focus were set to the top of the next record instead of the Arrival_Dt, which is in the middle. Please help.
 
Which control is the first one in the tab order?
You should be able to add this line to your code.
DoCmd.GoToControl "The Name Of The Control That is First"
 
I inserted an else statement if vbOk is true and inserted the GoToControl command but it goes to the control empl_number at the top of the present record. I want it to start at the top of the next record. Is there a way to tell Access to advance to the next record first and then setfocus?
 
Thanks for your help DJBummy. I used a GoToRecord command in the form after update event to advance to the next record and then used the setfocus method on empl_number.
 

Users who are viewing this thread

Back
Top Bottom