Selecting multiple checkboxes

goldres

New member
Local time
Today, 07:56
Joined
Oct 10, 2013
Messages
8
Hi

I have a form that has three checkboxes (IDDocument, DrivingLicence and Certification) on it. What the form is looking to do is based on the selection it will open a scanned document of the requested documents. There are 5 permutations that could be selected (either first on only, second one only, third one only, first and second and first and third). How do I code the IF Statement this so that the system will look at the different options and then do certain things accordingly.

The code I have at the moment is:

Public Sub ProcessRequest_Click()

Dim Form1 As String
Dim Form2 As String

Path = "Staff\" & Me!EmployeeName & "\"

If Me!IDDocument = True And Me!DrivingLicence = False And Me!Certification = False Then

Do one thing

ElseIf Me!IDDocument = False And Me!DrivingLicence = True And Me!Certification = False Then

Do a second thing

ElseIf Me!IDDocument = False And Me!DrivingLicence = False And Me!Certification = True Then

Do a thrid thing

ElseIf Me!IDDocument = True And Me!DrivingLicence = True And Me!Certification = False Then

Do a forth thing

ElseIf Me!IDDocument = True And Me!DrivingLicence = False And Me!Certification = True Then

Do a final thing

End If


End Sub

All the bits work (the form stuff) but my IF statements are not working. It seems that access is seeing the checkboxes as null and so the IF is not working when i check box 1 and leave the other two unchecked.

Please can you assist me with this

Thanks

Gary
 
If there are unbound check boxes (and seems to be), until your first check will have, indeed, a Null value.

There are 2 solution here:

1) Use NZ() function
Code:
Dim IDdoc As Boolean, DrivLic As Boolean, Cert As Boolean
  IDdoc = NZ(Me!IDDocument,0)
  DrivLic = NZ(Me!DrivingLicence ,0)
  Cert = NZ(Me!Certification ,0)

  If IDdoc And Not DrivLic  And Not Cert  Then
    Do one thing
    ElseIf Not IDdoc  And DrivLic  And Not Cert  Then
      Do a second thing
      ElseIf Not IDdoc  And Not DrivLic  And Cert  Then
        Do a thrid thing
         ElseIf IDdoc DrivLic  And Not Cert  Then
          Do a forth thing
          ElseIf IDdoc  And Not DrivLic  And Cert  Then
            Do a final thing
  End If
2) Set the Default Values for all checkboxes to False (in Property Sheet) then use the same code without NZs:
Code:
Dim IDdoc As Boolean, DrivLic As Boolean, Cert As Boolean
  IDdoc = Me!IDDocument
  DrivLic = Me!DrivingLicence
  Cert = Me!Certification

  If .........
You can avoid the ElseIf statements:
Code:
Private Sub DoSomething()
Dim IDdoc As Boolean, DrivLic As Boolean, Cert As Boolean
  IDdoc = Me!IDDocument
  DrivLic = Me!DrivingLicence
  Cert = Me!Certification

  If IDdoc And Not DrivLic  And Not Cert  Then
    Do one thing
Exit Sub
  End If

  If Not IDdoc  And DrivLic  And Not Cert  Then
    Do a second thing
Exit Sub
  End If

 If Not IDdoc  And Not DrivLic  And Cert  Then
    Do a thrid thing
Exit Sub
  End If

  If IDdoc DrivLic  And Not Cert  Then
    Do a forth thing
Exit Sub
  End If

  Do a final thing

End Sub
 

Users who are viewing this thread

Back
Top Bottom