GOTO a specific part of another command's code

  • Thread starter Thread starter ILCSP
  • Start date Start date
I

ILCSP

Hello, I have a typical form with some command buttons- New, Save,
Reset, Update, Exit, Delete, etc. and some of them like Save, Delete
and Update have a vbYesNo question that asks the user whether to carry
on with the action (i.e. "Do you want to Update this record?" Yes - No)
and they work as they should: if the user click Yes the record gets
updated, otherwise, it does not.

However, when I check for changes for the current record (before
creating a new record or exiting the form) I also let the user know
whether the current record was modified, but not saved and I ask.. Do
you want to save it? Yes - No. If they click the vbYes button, then
they're directed to the Update button's code (Update_Click) which has
its own question as stated in the first paragraph of this post.

Therefore, the user gets the update question and has to click Yes again
to update and that can be pretty annoying for them.

Is there a way to GOTO a specific part of the code in the Update
command button so they don't have to see its own question?

This is part of the update button code:

Private Sub Update_Click ()

' Get confirmation
strMsg = "Do you want to Update this record?"
If MsgBox(strMsg, vbYesNo + vbQuestion + vbDefaultButton2, "Delete
Record?") = vbYes Then

(X) I want the GOTO connector to start from here!
Upd:
..and here I call the store procedure that updates the record

End If

End Sub
________________________________

What I want to do is that when I'm checking for changes and I ask the
user if they want to update and they agree, I should go directly to the
part of the code in the update button where I call the store procedure.
I want to skip the Update question to update because the user already
confirmed their updating intentions.

I know this is probably a very easy line like 'GoTo Update_Click
something Upd:'

Again, thanks for all your help.


Max
 
If I understand your question correctly, then send the user to the Upd:
procedure directly from the Save question. If the procedure is in the
Update Click event, then you need to create it as a subroutine, and call it
from the Save click event and the Update click event...
 
Hi Max

define a global variable at the top of the form

Dim gBooSkipMsg as boolean

In any code where you send it to update and you want to skip
the message:
'------------------------------
gBooSkipMsg = true
'------------------------------

Then, in the Update event

'------------------------------
If nz(gBooSkipMsg, false) then
strMsg = "Do you want to Update this record?"
If MsgBox(strMsg, vbYesNo + vbQuestion +
vbDefaultButton2, "Update Record?") = vbNo Then
Cancel = true
'if you also want to undo changes to record
me.undo
exit sub
end if
End if

'your update code
'------------------------------

Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
(e-mail address removed)
 
hi Max,

Therefore, the user gets the update question and has to click Yes again
to update and that can be pretty annoying for them.
Is there a way to GOTO a specific part of the code in the Update
command button so they don't have to see its own question?
Separate the presentational code from functional code.

Create an independend update procedure (Sub UpdateData()). Call it
instead of the event procedure Update_Click() and use it also in the
Update_Click() event.


mfG
--> stefan <--
 
Hi guys, I believe separating presentation code from functional code is
the best choice for me. I will give it a try.

Thanks for replying.
 
Back
Top