Set Focus Assistance Needed Urgently

  • Thread starter Thread starter Jani
  • Start date Start date
J

Jani

Need some assistance on getting this coding to work right on this form.
Basically, if the location and date are already in the SQL table, the 'Date1'
and 'Location' fields need to be cleared on the form and the focus be in the
'Location' field. Here's my latest (but obviously not greatest) code which is
giving a RunTime 2108 error 'Save the field before you execute the
GoToControl action... or the SetFocus method.' Thanks so much in advance! I
must also confess that I have posted this to a couple other groups a few days
ago but never got an answer.

Private Sub txtDate1_BeforeUpdate(Cancel As Integer)
If Not IsNull(DLookup("[Date1]", "dbo_uSus_ActualData", "[Date1] = '" &
Me.txtDate1 & "' And [Location] = '" & Me.txtLocation & "'")) Then

MsgBox "Some or all of the data for this date and location are already in
the SQL table. Use the 'Edit Monthly Data for Selected Location' button on
the right to enter additional data or edit data for this month and location."

Me.Undo

Cancel = True
Me.txtLocation.SetFocus

End If

End Sub
 
Jani said:
Need some assistance on getting this coding to work right on this form.
Basically, if the location and date are already in the SQL table, the 'Date1'
and 'Location' fields need to be cleared on the form and the focus be in the
'Location' field. Here's my latest (but obviously not greatest) code which is
giving a RunTime 2108 error 'Save the field before you execute the
GoToControl action... or the SetFocus method.' Thanks so much in advance! I
must also confess that I have posted this to a couple other groups a few days
ago but never got an answer.

Private Sub txtDate1_BeforeUpdate(Cancel As Integer)
If Not IsNull(DLookup("[Date1]", "dbo_uSus_ActualData", "[Date1] = '" &
Me.txtDate1 & "' And [Location] = '" & Me.txtLocation & "'")) Then

MsgBox "Some or all of the data for this date and location are already in
the SQL table. Use the 'Edit Monthly Data for Selected Location' button on
the right to enter additional data or edit data for this month and location."

Me.Undo

Cancel = True
Me.txtLocation.SetFocus

End If

End Sub


I son't understand what you are trying to accomplish, but
the BeforeUpdate event is too early for it. Try using the
AfterUpdate event instead.
 
Back
Top