Message Box

  • Thread starter Thread starter Jeanne
  • Start date Start date
J

Jeanne

How do I get a message box to appear as soon as a new record is requested
within a form? I have the macro ready, I'm just not sure where to attach it
so that it runs immediately when the "new record" button is pushed before any
information is entered.
 
I would use an Event Procedure, and test for NewRecord in the form's Current
event:

If Me.NewRecord Then
MsgBox "MessageText",vbInformation,"Title"
End If

vbInformation could be another choice such as vbExclamation; I provided it
by way of example only.

You could also add it to the commmand button's Click event, in which case
you don't need to test for a new record.

What runs when you click the New button, a macro or an event procedure? If
the former I suppose you could call your message box macro from the macro,
or add the message box command to the macro. If the latter you could add a
MsgBox line to the event procedure as sketched above.

If the message box is information only, consider whether you may be annoying
users if they have to click through the same message box every time they
start a new record. You don't want to get users in the habit of treating
every pop-up as something they need to make go away as quickly as possible.
 
Hi Jeanne

Depending on if data has been added you could something like
If (Me.Dirty = True) Then
Me.Undo
End If


or you could use something like this to make it simpler for users to
understand what they are doing (change Button Name to what it is on your form)

Add this to the OnClick event of the button - remove all other code the
wizard adds for you.

Private Sub ButtonName_Click()
Dim msg, style, title, responce
msg = "Are you sure you want" & vbCrLf & "to add a new record" _
& vbCrLf & vbCrLf & "Select Yes to add a record" _
& vbCrLf & "Select No to cancel"
style = vbYesNo
title = "Message from Jeanne"
responce = MsgBox(msg, style, title)
If responce = vbYes Then
DoCmd.GoToRecord , , acNewRec
Else
Me.Undo
End If
End Sub
 
Back
Top