Conditional Macro Message Box on a Form

  • Thread starter Thread starter Sarah G
  • Start date Start date
S

Sarah G

I am have set a message box on a form but only want it to display if the
entry in the number field is >120.
I assume I need to put this macro in the On Update line in Properties but am
unsure of how to write the expression. I have used basic expressions before
but never one that included a macro
If Weight >120 run macro "weight"
Hope you can help
 
I am have set a message box on a form but only want it to display if the
entry in the number field is >120.
I assume I need to put this macro in the On Update line in Properties but am
unsure of how to write the expression. I have used basic expressions before
but never one that included a macro
If Weight >120 run macro "weight"
Hope you can help

There is no On Update property. There is an AfterUpdate property.

On the [NumberField] property sheet, select the Event tab.
On the AfterUpdate event line write
[Event Procedure]
Then click on the little button with the 3 dots that appears on that
line.
When the code window opens, the cursor will be flashing between 2
already existing lines of code.

Between those 2 lines, write

If Me![NumberField] >120 then
MsgBox "Place your message here."
End If

Change [NumberField] to the actual name of the control on your form.
Exit the code window.

You can substitute the actual message of your current macro message
box, but that's all you need. You do not need your macro.
 
.. Yes I meant After Update but I'm glad you knew what I meant. That has
worked well. Thank you so much

fredg said:
I am have set a message box on a form but only want it to display if the
entry in the number field is >120.
I assume I need to put this macro in the On Update line in Properties but am
unsure of how to write the expression. I have used basic expressions before
but never one that included a macro
If Weight >120 run macro "weight"
Hope you can help

There is no On Update property. There is an AfterUpdate property.

On the [NumberField] property sheet, select the Event tab.
On the AfterUpdate event line write
[Event Procedure]
Then click on the little button with the 3 dots that appears on that
line.
When the code window opens, the cursor will be flashing between 2
already existing lines of code.

Between those 2 lines, write

If Me![NumberField] >120 then
MsgBox "Place your message here."
End If

Change [NumberField] to the actual name of the control on your form.
Exit the code window.

You can substitute the actual message of your current macro message
box, but that's all you need. You do not need your macro.
 
Sarah,
Depending on your needs ie: the weight macro message, you might be better
off putting the code in the BeforeUpdate event. This will allow you to
Cancel=True & Me.Undo to reverse the errant data.

the AfterUpdate event occurs, as it's name After the data has been updated.
The BeforeUpdate allows you to test the data value and then reject it IF it
doesn't meet criteria.

Again, just a thought that may or may not be applicable for your purposes.

--
Dan Knight



Sarah G said:
. Yes I meant After Update but I'm glad you knew what I meant. That has
worked well. Thank you so much

fredg said:
I am have set a message box on a form but only want it to display if the
entry in the number field is >120.
I assume I need to put this macro in the On Update line in Properties but am
unsure of how to write the expression. I have used basic expressions before
but never one that included a macro
If Weight >120 run macro "weight"
Hope you can help

There is no On Update property. There is an AfterUpdate property.

On the [NumberField] property sheet, select the Event tab.
On the AfterUpdate event line write
[Event Procedure]
Then click on the little button with the 3 dots that appears on that
line.
When the code window opens, the cursor will be flashing between 2
already existing lines of code.

Between those 2 lines, write

If Me![NumberField] >120 then
MsgBox "Place your message here."
End If

Change [NumberField] to the actual name of the control on your form.
Exit the code window.

You can substitute the actual message of your current macro message
box, but that's all you need. You do not need your macro.
 
Back
Top