Set Focus Assistance Needed Urgently

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
 
M

Marshall Barton

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top