Message box question

  • Thread starter Thread starter Bruce
  • Start date Start date
B

Bruce

I have the following in the After Update event of a text
box:

If MsgBox("Completed?", vbYesNo) = vbYes Then
Me.txtNext.SetFocus
Else: {perform an action}
End If

Me.txtNext.SetFocus is, in effect, closing the message box
without taking any action. I would prefer to just close
the message box through code, but Me.txtNext.SetFocus is
what would happen in that case anyhow.

I would like for the message box to appear only if it is a
new record, not when editing an existing record (uncommon,
but it does need to happen sometimes). If it simplifies
the code, I have a text box that reads "New Record" only
when that is the case (it shows "Record X of Y"
otherwise). So what I need is maybe something like:

If Me.txtXofY = "New Record" Then
{run the code above}

As a general question, is there VBA code for "Do Nothing"?
 
Bruce said:
I have the following in the After Update event of a text
box:

If MsgBox("Completed?", vbYesNo) = vbYes Then
Me.txtNext.SetFocus
Else: {perform an action}
End If

Me.txtNext.SetFocus is, in effect, closing the message box
without taking any action. I would prefer to just close
the message box through code, but Me.txtNext.SetFocus is
what would happen in that case anyhow.

I would like for the message box to appear only if it is a
new record, not when editing an existing record (uncommon,
but it does need to happen sometimes). If it simplifies
the code, I have a text box that reads "New Record" only
when that is the case (it shows "Record X of Y"
otherwise). So what I need is maybe something like:

If Me.txtXofY = "New Record" Then
{run the code above}

As a general question, is there VBA code for "Do Nothing"?


If Me.NewRecord = True then
If MsgBox("Completed?", vbYesNo) = vbYes Then
Me.txtNext.SetFocus
End If
Endif

Ron
 
Thanks for the speedy reply. It is good to know the
syntax requirements are that simple for nesting If
statements. Do you happen to know if there is some sort
of VBA equivalent to "Do Nothing"? In other words, in my
example Me.txtNext.SetFocus means, in effect, "Pretend
this message box never appeared".
 
One way
IF a = True
'Do Nothing
Else
A=False
END IF

Or
IF A = False
A=False
End If

In other words, reverse the logic test.

In your specific example

If MsgBox("Completed?", vbYesNo) <> vbYes Then
{perform an action}
End if
 
Back
Top