Message Pop up for Records if not saved (1 Viewer)

SjCc

Registered User
Joined
Oct 5, 2017
Messages
66
I have a command button named "Go_Set" in a form named "Payments"
i want if the user forget to hit that command button which include an append query and refresh command the at the time of form close there need a pop up message box where if hits "YES" then this yes should hit command button "Go_Set" and donothing if no
 

The_Doc_Man

Happy Retired Curmudgeon
Joined
Feb 28, 2001
Messages
15,682
I'm not ENTIRELY clear on your intent, but I'm going to take a shot at it anyway.

You need to prevent navigation and premature closure of the form because those things will cause a "hidden" update. This prevention can be managed by event programming.

You put a "BEFORE UPDATE" event on the form that will fire before the form would do something to perform an update. If what you wanted to be has not been done yet, this particular event call includes a Cancel argument. If you return a value of -1 (or TRUE) to that argument, then Access will not allow the update to fire. If that event is the result of either navigation or a premature CLOSE action, it won't close so easily.

This implies that there will be code in the command button (? GO_SET, you called it? ) to set a flag that says, "Button was pushed." The button-click event for this button would do whatever you had it doing anyway - but you add one line to set the flag. Then the event code would check the flag before deciding whether to cancel the event or not.

To go along with this, you need to clear that flag in the form's "CURRENT" event because that is a moment when there is nothing to save on the form because the form and underlying record match.

And finally, where would this go? Since everything in question is form-related, you put the flag variable in the form's common declaration area that is at the front of the form's class module. Things declared in that area are still private to outside code but they are public within the confines of the form itself. So each routine can see the flag - the Current event, the Before_Update event, and the button OnClick event.

Your message box would go in the Before_Update event IF you decide to cancel the update. Before you return from the event, you return -1 to Cancel and you pop up your desired message box.
 

vba_php

Custom Title Here
Joined
Oct 6, 2019
Messages
2,081
i want if the user forget to hit that command button which include an append query and refresh command the at the time of form close there need a pop up message box where if hits "YES" then this yes should hit command button "Go_Set" and donothing if no
sjCC, popup messages have 2 forms in access => the "input()" function in VBA and the "msgbox()" function. as far as I know, input() does not have options for the user, so you're stuck with msgbox(). I would highly doubt you can run code that is behind a button from an option press ("YES/NO") behind ANOTHER button. However, what you can do is run the code you currently have behind "go_Set" in a module of itself and point to it when the user clicks "YES" in your message box popup "mgsbox()". so, you would write:
Code:
private sub form_close()
'perform check here to see if the user clicked the button (I can't possibly know what ur checking)
   if msgbox("oops!  you forgot to push the button!  " & vbcrlf & vbcrlf & _
             "would you like us to take care of that for you?", vbyesnocancel, vbinformation) = vbyes then
      'RUN GENIUS APPEND QUERY HERE
   else
      'do nothing, the user cares nothing about the data they entered
   end if
end sub
i'm almost sure this will work, however don't quote me as it's been a while since I've done any of this. I'm sure The Doc Man will correct me if I'm made an error.
 

isladogs

CID Moderator
Staff member
Joined
Jan 14, 2017
Messages
12,362
Almost ... you only want 2 choices and you need a + sign as below
Replace vbyesnocancel, vbinformation with e,g, vbYesNo+vbExclamation

BUT do you really need to offer a choice? Should the data just be saved automatically?
 

vba_php

Custom Title Here
Joined
Oct 6, 2019
Messages
2,081
Replace vbyesnocancel, vbinformation with e,g, vbYesNo+vbExclamation
Should the data just be saved automatically?
oh no, really? as you can see, i hard coded it into the post without a file reference, as it's all in lower case. and YES, the data is saved automatically anyway, if it's a bound form which i'm guessing his is. in that case, Richard's knowledge would come into play and he would have to use ME.UNDO or CANCEL = TRUE (which I still don't get)
 

SjCc

Registered User
Joined
Oct 5, 2017
Messages
66
oh no, really? as you can see, i hard coded it into the post without a file reference, as it's all in lower case. and YES, the data is saved automatically anyway, if it's a bound form which i'm guessing his is. in that case, Richard's knowledge would come into play and he would have to use ME.UNDO or CANCEL = TRUE (which I still don't get)
Yes no msgbox worked for me as per my requirement..

Thanks for the support indeed..
 

adewale4favour

Registered User
Joined
Aug 9, 2019
Messages
16
Not very clear as to what you want the code to do, but what I can say is, if why not put the code behind the form, OnClose Event, and perform all the queries once this form is closed?


You may bear in mind that, the AppendQuery will need to do necessary checks, for records that do not need to be kept, if they don't change. You need more help?



Regards
Michael
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom