MSgBox Yes No

  • Thread starter Thread starter Irv1010
  • Start date Start date
I

Irv1010

I have a form with a next appointment field [NextApptDate]. The next
appointment date should normally be less than 21 days after the current date.
How do I create a MsgBox that will appear if the appointment date is over 21
days. i.e. "The next appointment for this client is currently more than 21
days in the future. Are you sure that this date is correct?". The user
would then be able to select "Yes" which would continue to save and close the
form or "No" which would keep the form open.

Your help is greatly appreciated.
 
in the *form's* BeforeUpdate event procedure, add

If MsgBox("The next appointment for this client is " _
& "currently more than 21 days in the future. " _
& "Are you sure that this date is correct?", _
vbYesNo+vbDefaultButton2) = vbNo Then
Cancel = True
Me!NextApptDate.Undo
Me!NextApptDate.SetFocus
End If

recommend you read up on the MsgBox() function in VBA Help so you'll
understand the arguments.

hth
 
Irv,

(Note to Tina: Watch your head! :-) )

Tina has given you a VBA solution. In a macro, you can use a Condition,
something like this:
MsgBox("Over 21 days. Are you sure?",292,"Confirm date")=7

In this example, the 6 is a constant that represents No, so the
associated macro action would only proceed if the user clicks No in the
message box.

So I would construct the macro like this:

Condition: [NextApptDate]-Date()<21
Action: StopMacro
Condition: MsgBox("Over 21 days. Are you sure?",292,"Confirm date")=7
Action: CancelEvent
 
duh - i didn't even think of using the MsgBox() function outside of a
module...and my head's still sore from the last time!! <g>


Steve Schapel said:
Irv,

(Note to Tina: Watch your head! :-) )

Tina has given you a VBA solution. In a macro, you can use a Condition,
something like this:
MsgBox("Over 21 days. Are you sure?",292,"Confirm date")=7

In this example, the 6 is a constant that represents No, so the
associated macro action would only proceed if the user clicks No in the
message box.

So I would construct the macro like this:

Condition: [NextApptDate]-Date()<21
Action: StopMacro
Condition: MsgBox("Over 21 days. Are you sure?",292,"Confirm date")=7
Action: CancelEvent

--
Steve Schapel, Microsoft Access MVP
in the *form's* BeforeUpdate event procedure, add

If MsgBox("The next appointment for this client is " _
& "currently more than 21 days in the future. " _
& "Are you sure that this date is correct?", _
vbYesNo+vbDefaultButton2) = vbNo Then
Cancel = True
Me!NextApptDate.Undo
Me!NextApptDate.SetFocus
End If

recommend you read up on the MsgBox() function in VBA Help so you'll
understand the arguments.
 
Back
Top