Access- Add Message Box to Code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am currently designing a Reciept Database. The main form has a button that
automatically inserts the next reciept number which is located in a seperate
table. I am wanting to put in a Warning Message to display when a user
clicks the Add Reciept Button to prevent users from accidently clicking the
Add Reciept Button and using up a number. Below is the code I am using for
the Add Receipt Number Button:
rivate Sub Command14_Click() 'insert invoice header button


Dim strWk As String
Dim lOrderNo As Long 'to hold the returned returncode/gen'ed
number


strWk = "INSERT INTO tblOrders(RctNbr) VALUES (xGenNxtNbr());"

lOrderNo = xGenNxtNbr(strWk, "tblOrders", "RctNbr") 'x will be 0 or the
generated order number

Me.Reciept_Number = lOrderNo 'show rc or
nbr to user

End Sub

Is it possible to create a Yes, No (Or Yes/No/Cancel) Message so that if a
user accidently pressed the button there is the option for them to click No
and cancel the execution of the code, and if they click yes, for the process
to resume? I don't know much about VB so any help would be greatly
appreciated. Thankyou.
 
-----Original Message-----
Is it possible to create a Yes, No (Or Yes/No/Cancel) Message so that if a
user accidently pressed the button there is the option for them to click No
and cancel the execution of the code, and if they click yes, for the process
to resume? I don't know much about VB so any help would be greatly
appreciated. Thankyou.
.
Hi Matt,

try...

if msgbox("Do you really want to do this?",
vbquestion+vbokcancel,"Insert Next Reciept")=vbok then

' code for the insert

end if

....
Luck
Jonathan
 
This worked great, The message box comes up, however if you click OK or
Cancel it still adds in the number into the reciept field. Is there a way
that if OK is clicked, it continues to execute the code and if Cancel is
clicked, it stops the Reciept Number from being created and inserted into the
form?
 
Matt,

The code for the insert should be inside the message box question code.

Try this: (watch for line wrap)
'---------------------
Private Sub Command14_Click() 'insert invoice header button

Dim strWk As String
Dim lOrderNo As Long 'to hold the returned returncode/gen'ed
number

if msgbox("Do you really want to do this?", vbquestion+vbokcancel,"Insert
Next Reciept")=vbok then

' code for the insert
strWk = "INSERT INTO tblOrders(RctNbr) VALUES (xGenNxtNbr());"

'x will be 0 or the generated order number
lOrderNo = xGenNxtNbr(strWk, "tblOrders", "RctNbr")

Me.Reciept_Number = lOrderNo 'show rc or nbr to user

end if
End Sub
'----------------

HTH
Steve
 
If msgbox("do you wish to continue?",vbyesno) = vbyes then
'* Continue
else
msgbox "Action cancelled."
exit sub
end if

Hope this helps,

Peter De Baets
Peter's Software - MS Access Tools for Developers
http://www.peterssoftware.com
 
Back
Top