exiting private sub without saving (1 Viewer)

ypma

Registered User.
Local time
Today, 09:37
Joined
Apr 13, 2012
Messages
643
Seasonal Greetings . i have a small procedure error . The scenario is when a states is change to Booked . After update, actions programmed work as expected. I now wish to place a before update question and if the answer is Yes the sub is exited, without saving the status Booked.

Code:
Private Sub Status_BeforeUpdate(Cancel As Integer)

    If Me.Status = "Booked" And IsNull(txtVulnerable) Then
        If MsgBox("Is this client Volnerable", vbYesNo + vbQuestion) = vbYes Then
            MsgBox "You have checked Yes. Now complete the volnerable text box"
        End If
    End If

    Exit Sub
        
        DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
        Me.txtVulnerable.SetFocus    '  VBA Command to be executed if Yes is selected

End Sub

When running the sub the before update runs first and then carry's on to the after update actions, when i wish it to exit the sub and not saved the booked status.

Advise would be appreciated.

Regard Ypma
 
Last edited by a moderator:

ypma

Registered User.
Local time
Today, 09:37
Joined
Apr 13, 2012
Messages
643
Uncle Gizmo : Thank you for your reply. Not quite what i am trying to achieve , i wish for my procedure to cancel and not save the change,. if the answer if Yes and only resume if Answer is No . My coding seems to resume, even if answer is Yes . Should i be placing the script in on click event ?

Regards Ypma
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 09:37
Joined
Jul 9, 2003
Messages
16,285
I think the first thing to do is write your question out differently. Explaining what you want to happen in terms of event you are already Calling is probably muddying the waters. Please explain the process, what you do, what you input, the output you expect and the conditions that control the output.
 

jdraw

Super Moderator
Staff member
Local time
Today, 04:37
Joined
Jan 23, 2006
Messages
15,383
ypma,
I agree with Tony -- write down what you want to do, make a simple flow chart for the logic/steps involved, test it with pencil, paper and simple data, adjust until it does/represents what you need, then go to coding.

As for exiting the BeforeUpdate, see this link

Good luck with your project.
 

ypma

Registered User.
Local time
Today, 09:37
Joined
Apr 13, 2012
Messages
643
JDraw. Thank you for your advice. i mistakenly thought my initial post was self explanatory,which it obviously was not . i will approach the problem from a different angle and if successful, i will this post as solved .

Regards Ypma
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 04:37
Joined
May 21, 2018
Messages
8,554
As pointed out by Gasman you have to Cancel the event. Exiting the sub only stops the code and does not stop the event of updating. I agree this should be in the forms before update. You do not want to cancel the status update, but you want to cancel the form update forcing them to fill out required fields.
 

jdraw

Super Moderator
Staff member
Local time
Today, 04:37
Joined
Jan 23, 2006
Messages
15,383
I concur Gasman. I thought the Exit Sub was in the wrong place in the logic, and also that there was no Cancel=True to abort the sub.
I'm seeing (or think I'm seeing) a lot of posts recently where
-the logic either doesn't make sense or hasn't been "tested" with sample data
-the OP has jumped into physical Access hoping for a miracle before doing analysis/design
-there is an assumption by the OP that readers are clairvoyant and understand the issue, the OP, the environment, the details of the requirement, and all the things that led up to his/her posting--"which is only true part of the time"
 

ypma

Registered User.
Local time
Today, 09:37
Joined
Apr 13, 2012
Messages
643
MajP. You are correct i failed to use Cancel = True?. i am marking this post as Solved to avoid any more flack from jdraw.

Regards Ypma
 

jdraw

Super Moderator
Staff member
Local time
Today, 04:37
Joined
Jan 23, 2006
Messages
15,383
ypma,
I did not mean to offend you, sorry for any miscommunication. I was trying to say there was a lack of clarity in your post, which Tony had mentioned. The link I offered in post#5
was to a code example with the Cancel and Exit, which I thought would help you resolve your issue.
Your post#6, seemed to say (to me) that the response was unhelpful and that you would find a different plan of attack.

Gasman and MajP also commented on the Cancel = True.

My comments in #9 were not directed at/to you, but a more summary of things that seem to be happening with more frequency than usual and related to Gasman's post/thinking.

None was intended as flack.
Good luck with your project.
 

ypma

Registered User.
Local time
Today, 09:37
Joined
Apr 13, 2012
Messages
643
jdraw: Thank you for putting your point of view across, i am guilty of expecting too much from the professionals members within this forum whom i hold in the highest esteem. In my own mitigation i am a part time user and help friend and family who use Access . As i approach my 80th birthday i know i am not the sharpest pencil in the box.

Regarding your op 4 , i thanked you for your advice and no way did i think your response was unhelpful, it was the fact that link you provided did not solve my question .

I hope this clears the and we can move on.

Happy New Year

Ypma
 

jdraw

Super Moderator
Staff member
Local time
Today, 04:37
Joined
Jan 23, 2006
Messages
15,383
10-4. Thanks for posting.
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:37
Joined
Sep 21, 2011
Messages
14,350
Regarding your op 4 , i thanked you for your advice and no way did i think your response was unhelpful, it was the fact that link you provided did not solve my question .

Ypma

To be fair, that link mentions Cancel twice and the correct placement of Exit Sub.? :confused:
 

Users who are viewing this thread

Top Bottom