BeforeUpdate and Setfocus

A

a235728

After updating a record and then navigating to another record via the
navigation buttons, I want to check to make sure that the user completed the
required fields before I allow them to change records. The problem is that
when I click on one of the navigation buttons, it then goes through this
event below and if it is good and saved, it doesn't change records. I'm
assuming, because I'm changing the focus to a control and it doesn't know to
change records after this code.

I just want it to continue to change records if it saves.

Here is the code:

If MsgBox("Changes have been made to this record." _
& vbCrLf & vbCrLf & "Do you want to save these changes?" _
, vbYesNo, "Changes Made...") = vbYes Then

If Len(cboprovider.Text) = 0 Then
MsgBox "Make a selection for Provider", vbOKOnly, "Provider Error"
Cancel = True
Exit Sub
End If
Else
DoCmd.RunCommand acCmdUndo
End If

Thanks

Stephen Shepherd
 
J

Jeanette Cunningham

Hi a235728,

there is an event on forms that does exactly what you need - it is called
Before Update.
Put your code on the before update event (of the form - not the control).
Something like this example:

Private Sub Form_BeforeUpdate(Cancel As True)
If Len(Me.cboprovider.Text) = 0 Then
MsgBox "Make a selection for Provider", vbOKOnly, "Provider Error"
Cancel = True
Else

End If
End Sub

The user won't be able to go to another record or close the form if the
provider control is empty.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
A

a235728

I forgot to mention, that is where I have the code. I have it in the
BeforeUpdate, but I have to set the focus to that field before I can access
it. I get an error if I don't. Is there away around this. I think this is
what is causing it to not navigate to the next record after it saves.

Thanks Jeanette

Jeanette said:
Hi a235728,

there is an event on forms that does exactly what you need - it is called
Before Update.
Put your code on the before update event (of the form - not the control).
Something like this example:

Private Sub Form_BeforeUpdate(Cancel As True)
If Len(Me.cboprovider.Text) = 0 Then
MsgBox "Make a selection for Provider", vbOKOnly, "Provider Error"
Cancel = True
Else

End If
End Sub

The user won't be able to go to another record or close the form if the
provider control is empty.

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
After updating a record and then navigating to another record via the
navigation buttons, I want to check to make sure that the user completed
[quoted text clipped - 27 lines]
Stephen Shepherd
 
D

Dirk Goldgar

"a235728" wrote in message news:88eeac641e1b0@uwe...
After updating a record and then navigating to another record via the
navigation buttons, I want to check to make sure that the user completed
the
required fields before I allow them to change records. The problem is
that
when I click on one of the navigation buttons, it then goes through this
event below and if it is good and saved, it doesn't change records. I'm
assuming, because I'm changing the focus to a control and it doesn't know
to
change records after this code.

I just want it to continue to change records if it saves.

Here is the code:

If MsgBox("Changes have been made to this record." _
& vbCrLf & vbCrLf & "Do you want to save these changes?" _
, vbYesNo, "Changes Made...") = vbYes Then

If Len(cboprovider.Text) = 0 Then
MsgBox "Make a selection for Provider", vbOKOnly, "Provider Error"
Cancel = True
Exit Sub
End If
Else
DoCmd.RunCommand acCmdUndo
End If

Thanks

Stephen Shepherd

Don't use the control's Text property -- that will relieve you of the need
to SetFocus to it. Instead, use the Value property of the control, which is
its default property, and check to see whether it is Null.

If IsNull(Me!cboprovider) Then
 
A

a235728

PERFECT!!!! Thank you so much!

Dirk said:
After updating a record and then navigating to another record via the
navigation buttons, I want to check to make sure that the user completed
[quoted text clipped - 27 lines]
Stephen Shepherd

Don't use the control's Text property -- that will relieve you of the need
to SetFocus to it. Instead, use the Value property of the control, which is
its default property, and check to see whether it is Null.

If IsNull(Me!cboprovider) Then
 

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