Test that atleast One Checkbox is checked

bconner

Registered User.
Local time
Yesterday, 18:00
Joined
Dec 22, 2008
Messages
183
I am trying to make sure the user selects at least one of the Reason Check Boxes before sending and email. When I leave all three Reason check boxes unchecked the email still sends, I can't figure out what I am doing wrong..... I am using the If And statements and have it set to throw up a message box if atleast one box isn't checked..


Code:
Dim olApp As Object
Dim objMail As Object
Dim strEmailBody As String
 
'Test to make sure a reason box is checked
 
If (Check_Add_New_Auditor_User = False _
And Check_Add_New_Error_Code = False _
And Check_Misc_Issue = False) = True Then
 
MsgBox "Please Check a Reason for this Email"
 
Else
 
strEmailBody = Nz(txt_Support_Message, "Add Detailed Message Here")
 
On Error Resume Next 'Keep going if there is an error
Set olApp = GetObject(, "Outlook.Application") 'See if Outlook is open
 
If Err Then 'Outlook is not open
Set olApp = CreateObject("Outlook.Application") 'Create a new instance of Outlook
End If
'Create e-mail item
Set objMail = olApp.CreateItem(olMailItem)
With objMail
.To = "bconner@ameripath.com;swoodring@ameripath.com"
.Body = strEmailBody
.display
End With
If Check_Add_New_Auditor_User = -1 Then
   objMail.Subject = "Add New Auditor/User"
Else
    If Check_Add_New_Error_Code = -1 Then
       objMail.Subject = "Add New Error Code"
Else
    If Check_Misc_Issue = -1 Then
       objMail.Subject = "Misc Issue"
End If
End If
End If
End If
End Sub


I even tried:
If (Check_Add_New_Auditor_User = False _
And Check_Add_New_Error_Code = False _
And Check_Misc_Issue = False) Then
 
Have you tried putting the .value propererty at the end of each checkbox's name?
 
I am using the If And statements and have it set to throw up a message box if atleast one box isn't checked

Not quite. Your condition in the code says if ALL three CheckBoxes are in unchecked state simultaneously.
 
Tried adding the .value like below and it still didn't work

Code:
If (Check_Add_New_Auditor_User.Value = False _
And Check_Add_New_Error_Code.Value = False _
And Check_Misc_Issue.Value = False) = True Then
MsgBox "Please Check a Reason for this Email"

Else

even tried

Code:
If (Check_Add_New_Auditor_User.Value = False _
And Check_Add_New_Error_Code.Value = False _
And Check_Misc_Issue.Value = False) Then
MsgBox "Please Check a Reason for this Email"

Else
 
As Access handles True as -1 and False as 0 this should work (untested).

Code:
If (Check_Add_New_Auditor_User + Check_Add_New_Error_Code + Check_Misc_Issue) =  0 Then
   MsgBox "Please Check a Reason for this Email"
Else
[/
 
If you can only have one reason then use an Option Group and test the group's value is not Null. (You can only select one checkbox though.)

Otherwise sum them as suggested by PeterF.

Have you tried putting the .value propererty at the end of each checkbox's name?

Value is the default property for all controls that have that property so it is not required.

The only place it is really needed is when using the With Block in VBA.

Code:
With MyControl
   .Enabled = False
   .Value = 1
End With
 

Users who are viewing this thread

Back
Top Bottom