MsgBox

B

Brian_M

Hi all,

I've been rummaging around the site a lot in the last few weeks, you guys are
great!

Down to business:

I'm trying to create a MsgBox that will either warn the user that their data
changes weren't saved (likely due to referential integrity violation) or that
it was saved. I have the form all set, and am running the code from the
Submit button. I can make it warn (albeit in a shoddy manner) that the
changes have not saved, but I'm not sure how to go about running a case for
failed/correct entries. Ideally, when the record is updated correctly, the
Msg will say something to the tune of "Changes accepted" or something, just
as a confirmation that all went according to plan.

Here's what I've spliced together so far:
======================
Function Reset_Click()
On Error GoTo Err_Reset_Click

Dim strMsg As String
Dim i As Integer 'This was just because it wanted me to assign the MsgBox
value somewhere

DoCmd.GoToRecord , , acNewRec

Exit_Reset_Click:
Exit Function

Err_Reset_Click:

strMsg = "Your changes were not saved. The most likely cause of this is a
duplicate" & vbNewLine _
& "serial number. Please check your data and try to Submit again."
_

i = MsgBox(strMsg, vbOKOnly, "Changes Failed")

Resume Exit_Reset_Click

End Function
===========================

Thanks for the help!

Brian
 
A

Allen Browne

If you want to run checks to see if everything is okay, use the BeforeUpdate
event of the form. (There are so many ways the record can be saved, that
this is the only way to catch them all.)

If you want to notify the user that the save succeeded, use the form's
AfterUpdate event.
 
B

Brian_M

Ok, after thinking about it (and smacking myself on the forehead with a
resounding "DOH!") I realized that I could simply create a second msgbox
underneath.

DoCmd.GoToRecord , , acNewRec
i = MsgBox("Your changes have been saved.", vbOKOnly, "Changes Accepted")

Since the validation error would occur when it tried to run the new record,
it will skip to the error handling if there is a problem. The only thing that
I don't understand much right now then is why I need to assign it to an int
variable? Unless I'm missing something, it seems that most of the other
examples utilizing MsgBox that I've seen around here don't need to have this..
 
J

John Spencer

MsgBox "Your changes have been saved.", vbOKOnly, "Changes Accepted"

MsgBox is a function. When you put the parameters in parentheses, you are
saying you want the function's value returned for further processing. If
you don't put the parens in, then the value is not returned - that is for
practical purposes the function is treated as a sub.
--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
B

Brian_M via AccessMonster.com

Ah didn't realize that, thanks!

John said:
MsgBox is a function. When you put the parameters in parentheses, you are
saying you want the function's value returned for further processing.
 
G

George Nicholson

Since you are using vbOKOnly, the user only has one button to push so the
user's action is a given and you dont' need the return value. However, if
you used one of the other button type constants (vbOKCancel,
vbAbortRetryIgnore, vbYesNo...), you would want to capture that return value
(representing the user's selection), for further processing:

i = Msgbox("You're fired", vbAbortRetryIgnore + vbCritical)

Select Case i
Case vbAbort
'code for cancel
Case vbRetry
'code for start again
Case vbIgnore
'code for plow forward
End Select

HTH,
 

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