Code help needed on message box please

dxp

Registered User.
Local time
Yesterday, 16:12
Joined
Jun 5, 2006
Messages
62
Hi All, Is it possible to have just one instance of this message box fire when one or all or any number of the flags are triggered. At the moment if 2 flags are set then 2 messgage boxes appear,if 3 then 3 messages etc. My code at the moment is below to trigger the message box, hope I make my self clear;can it be tidied up?





private Sub Form_Current()
If Me.Flag1 = "Patient Alert. HIGH RISK. Med Hist" Then
MsgBox "**WARNING PATIENT ALERTS DETECTED**Read all patient alerts before treatment"
End If
If Me.Flag2 = "Patient Alert. ALLERGY. Med Cond" Then
MsgBox "**WARNING PATIENT ALERTS DETECTED**Read all patient alerts before treatment"
End If
If Me.Flag3 = "Patient Alert. Cat Score. LOW. Caution See Notes" Then
MsgBox "**WARNING PATIENT ALERTS DETECTED**Read all patient alerts before treatment"
End If
If Me.Flag4 = "Patient Alert. PATHOLOGY. Int/Ext Exam" Then
MsgBox "**WARNING PATIENT ALERTS DETECTED**Read all patient alerts before treatment"
End If
End Sub
 
Code:
Private Sub Form_Current()
    Dim blnAlert As Boolean
    Dim strAlert As String

    strAlert = "**WARNING PATIENT ALERTS DETECTED**Read all patient alerts before treatment"


    If Me.Flag1 = "Patient Alert. HIGH RISK. Med Hist" Then
        blnAlert = True
    End If
    If Me.Flag2 = "Patient Alert. ALLERGY. Med Cond" Then
        blnAlert = True
    End If
    If Me.Flag3 = "Patient Alert. Cat Score. LOW. Caution See Notes" Then
        blnAlert = True
    End If
    If Me.Flag4 = "Patient Alert. PATHOLOGY. Int/Ext Exam" Then
        blnAlert = True
    End If

    If blnAlert Then
        MsgBox strAlert, vbCritical, "Alerts Detected"
    End If
End Sub
 
This should work...more than one way to skin this cat though...

Code:
private Sub Form_Current()

If Me.Flag1 = "Patient Alert. HIGH RISK. Med Hist" Then
MsgBox "**WARNING PATIENT ALERTS DETECTED**Read all patient alerts before treatment",vbinformation
Else
If Me.Flag2 = "Patient Alert. ALLERGY. Med Cond" Then
MsgBox "**WARNING PATIENT ALERTS DETECTED**Read all patient alerts before treatment",vbinformation
Else
If Me.Flag3 = "Patient Alert. Cat Score. LOW. Caution See Notes" Then
MsgBox "**WARNING PATIENT ALERTS DETECTED**Read all patient alerts before treatment",vbinformation
Else
If Me.Flag4 = "Patient Alert. PATHOLOGY. Int/Ext Exam" Then
MsgBox "**WARNING PATIENT ALERTS DETECTED**Read all patient alerts before treatment",vbinformation
End If
End If
End If
End If

End Sub

It's ugly doing it this way. If you used a check box bound to a yes/no field for each flag (instead of a text field) you could do something a little more elegant.

For example:
Code:
dim show_message as integer
show_message = ABS(Me.Flag1 + Me.Flag2 + Me.Flag3 + Me.Flag4)
if show_message > 0 then
MsgBox "**WARNING PATIENT ALERTS DETECTED**Read all patient alerts before treatment",vbinformation
End if
Since the value of a yes/no field is -1 for true, and 0 for false, and your message does not change depending on which flag is triggered, you only need to know if the absolute value of the sum of the flags is greater than one and thereby show the message. Using a yes/no field for each flag will also save you several bytes per record compared to storing the text strings.
___________________________________
Ok...Bob beat me to the punch (he posted before I got done with my reply)...again! :)
 
Last edited:
Thanks guys, I shall give your examples a go now. Hopefuly I shall have only one message show no matter how many flags are triggered. I will let you know how it goes.
 
Thanks guys, I shall give your examples a go now. Hopefuly I shall have only one message show no matter how many flags are triggered. I will let you know how it goes.

If you use my code, only one message box is guaranteed since it's called only once.
 
Guys Thanks a million, I used Bobs code, works treat. Many thanks for your help.:D
 
Bob, heres a screen shot of your code in action! is it possible to have to lower case text on a seperate line instead of split like it is. Just for the sake of good design?
 
sorry,screen shot here now
 

Attachments

  • message screen shot.jpg
    message screen shot.jpg
    98.3 KB · Views: 122
got it now after a little trial and error, & vbCrLf &
 

Users who are viewing this thread

Back
Top Bottom