Msg box help

  • Thread starter Thread starter k.roberts
  • Start date Start date
K

k.roberts

I have created a field that prompts users for an analysis code from a
dropdown list of letters (A, B, C etc). I want a message to appear when
they select 'C' stating "Please ensure you have entered an enquiry
number...". What code do I put behind the AfterUpdate property to do
this?

Thanks
 
hi k.,

I have created a field that prompts users for an analysis code from a
dropdown list of letters (A, B, C etc). I want a message to appear when
they select 'C' stating "Please ensure you have entered an enquiry
number...". What code do I put behind the AfterUpdate property to do
this?
If DropDown.Value = "C" Then
MsgBox "Sure?", vbOkOnly
End If

mfG
--> stefan <--
 
Stefan's suggestion will work if you only want a message for "C". If you
have a message for more than one, there are a couple of ways you can do it.
One would be to make your combo box a 2 column combo with the letter as the
first column (column(0)) and the message in column(1). If there is no
message for a letter, make the second column a zero length string "". Then in
the after update event of your combo:

If Me.MyCombo.Column(1) <> vbNullString Then
MsgBox Me.MyCombo.Column(1)
End If

Another way would be to use a Select Case statement:

Dim strMsg as String

Select Case Me.MyCombo
Case "A"
strMsg = "A Message for A"
Case "B"
strMsg = "A Message for B"
Case "C"
strMsg = "A Messsage for C"
Case "E"
strMsg = "A Message for E"
Case Else
strMsg = vbNullString
End Select
If strMsg <> vbNullString Then
MsgBox strMsg
End If

Notice that in the second example, there is no check for "D". You would not
put checks for those letters you don't want a message for. Then the code
will fall to the Case Else and no nessage will be displayed.

My preference is the first example because there is less code.
 
Back
Top