Using IF and OR in the same statment?

dan231

Registered User.
Local time
Today, 15:12
Joined
Jan 8, 2008
Messages
158
I have a statement that calls a certain report. It is working, but I need to modify it for a new position.

The code is if the person teaching the class is the president, then use report 3. I need to add an OR if the person teaching is the Director, then use report 3.

The existing code:
Code:
If strEmployeeID <> intBFPRESIDENT Then
      txtCertificateType.Value = 3
End If
Can I just add an OR in there:
Code:
If strEmployeeID <> intBFPRESIDENT or If strEmployeeID <> intDIRECTOR Then
      txtCertificateType.Value = 3
End If
Yes, the intDIRECTOR has been defined.
Any pointers on this would be very much appreciated.
 
Yes you can use OR...but remove the second IF on the initial line:

If strEmployeeID <> intBFPRESIDENT or strEmployeeID <> intDIRECTOR Then

You could also use a Select Case statement. Less messy IMHO.

Code:
 
Thank you. I will give that a shot.
 
If strEmployeeID <> intBFPRESIDENT or strEmployeeID <> intDIRECTOR Then

Code:
[/quote]

This had no effect.  Maybe I'm not changing the right code portion.
Thanks again for your help.
 
no. here is the whole code section:
and while I'm looking at it, the changes are not here - they didn't save...??? ug!
Code:
Private Sub ProcessCertificatesByClass()
    Dim strPathAndFileName As String
    Dim strMailMergeDocName As String
    Dim strRptName As String
    Dim strNewDocName As String
    Dim appWord As Word.Application
    Dim docs As Word.Documents
    Dim i As Integer
    Dim aFileNum As Long
    Dim strRec As String
    Dim strQCQ As String
    Dim strQuote As String
    Dim strCourseID As String
    Dim strEmployeeID As String
    
    txtCertificateType.Value = 1
    cboGetCertificateName.Requery
    
    cboGetInstructorNames.Requery
    If cboGetInstructorNames.ListCount < 1 Then
        MsgBox "There is no Instructor for this Class: " & cboGetClasses.Column(1)
        Exit Sub
    End If
    
    strEmployeeID = cboGetInstructorNames.Column(1, 0)
    
    txtInstructorName.Value = Null
    
    For i = 0 To cboGetInstructorNames.ListCount - 1
        txtInstructorName.Value = txtInstructorName & cboGetInstructorNames.ItemData(i) & vbCrLf
    Next i
    
    txtInstructorName.Value = MID(txtInstructorName, 1, Len(txtInstructorName) - 2)
    
'    MsgBox "cboGetCertificateName.ListCount:  " & cboGetCertificateName.ListCount & vbCrLf & _
'        "txtCourseId: " & txtCourseId & vbCrLf & _
'        "cboGetClasses: " & [cboGetClasses]
    
'*************************************************************************************
'   If this is not a special certificate type (CECDP, PAP, IPLC, etc), the
'   query will return 0 recs, therefore, move zero to CourseID and get default
'   certificate.
'*************************************************************************************
    If cboGetCertificateName.ListCount < 1 Then
        txtCourseID.Value = 0
        
        If cboGetInstructorNames.ListCount > 1 Then
            txtCertificateType.Value = 3
        End If
        
        If strEmployeeID <> intBFPRESIDENT Then
            txtCertificateType.Value = 3
        End If
        
        If strEmployeeID <> intBFCADIRECTOR Then
            txtCertificateType.Value = 3
        End If
        
        cboGetCertificateName.Requery
        
        If cboGetCertificateName.ListCount < 1 Then
            MsgBox "Could NOT find default Certificate--exiting."
            Exit Sub
        End If
    End If
    
    strMailMergeDocName = cboGetCertificateName.ItemData(0)
    strQuote = """"
    strQCQ = strQuote & "," & strQuote
    
' 0 ClassScheduleID,
' 1 StudentName,
' 2 LastName,
' 3 StartDate,
' 4 EndDate,
' 5 ClassYear,
' 6 ClassMonth,
' 7 ClassDay,
' 8 EmployeeID,
' 9 StudentID,
' 10 Certification,
' 11 MembershipNumber,
' 12 CourseAIACourseNumber,
' 13 CourseContEdUnits,
' 14 CourseContactHours,
' 15 CourseLearningUnits
    
    lbxGetCertificateInfoByClass.Requery
    
    If lbxGetCertificateInfoByClass.ListCount < 1 Then
        MsgBox "No recs for this class--exiting."
        Exit Sub
    End If
    
    strPathAndFileName = "F:\solutions\B&FServices\StudentCertificate.txt"
    aFileNum = FreeFile
    Open strPathAndFileName For Output As #aFileNum
    
    For i = 0 To lbxGetCertificateInfoByClass.ListCount - 1
        strRec = "" & strQuote
        strRec = strRec & lbxGetCertificateInfoByClass.Column(0, i) & strQCQ
        strRec = strRec & lbxGetCertificateInfoByClass.Column(1, i) & strQCQ
        strRec = strRec & lbxGetCertificateInfoByClass.Column(2, i) & strQCQ
        strRec = strRec & lbxGetCertificateInfoByClass.Column(3, i) & strQCQ
        strRec = strRec & lbxGetCertificateInfoByClass.Column(4, i) & strQCQ
        strRec = strRec & lbxGetCertificateInfoByClass.Column(5, i) & strQCQ
        strRec = strRec & lbxGetCertificateInfoByClass.Column(6, i) & strQCQ
        strRec = strRec & lbxGetCertificateInfoByClass.Column(7, i) & strQCQ
        strRec = strRec & lbxGetCertificateInfoByClass.Column(8, i) & strQCQ
        strRec = strRec & lbxGetCertificateInfoByClass.Column(9, i) & strQCQ
        strRec = strRec & lbxGetCertificateInfoByClass.Column(10, i) & strQCQ
        strRec = strRec & lbxGetCertificateInfoByClass.Column(11, i) & strQCQ
        strRec = strRec & lbxGetCertificateInfoByClass.Column(12, i) & strQCQ
        strRec = strRec & lbxGetCertificateInfoByClass.Column(13, i) & strQCQ
        strRec = strRec & lbxGetCertificateInfoByClass.Column(14, i) & strQCQ
        strRec = strRec & lbxGetCertificateInfoByClass.Column(15, i) & strQCQ
        strRec = strRec & lbxGetCertificateInfoByClass.Column(16, i) & strQCQ
        strRec = strRec & lbxGetCertificateInfoByClass.Column(17, i) & strQCQ
        strRec = strRec & lbxGetCertificateInfoByClass.Column(18, i) & strQCQ
        strRec = strRec & lbxGetCertificateInfoByClass.Column(19, i) & strQCQ
        strRec = strRec & lbxGetCertificateInfoByClass.Column(20, i) & strQCQ
        strRec = strRec & lbxGetCertificateInfoByClass.Column(21, i) & strQCQ
        strRec = strRec & lbxGetCertificateInfoByClass.Column(22, i) & strQCQ
        strRec = strRec & lbxGetCertificateInfoByClass.Column(23, i) & strQCQ
        strRec = strRec & lbxGetCertificateInfoByClass.Column(24, i) & strQCQ
        strRec = strRec & lbxGetCertificateInfoByClass.Column(25, i) & strQuote
            
'        MsgBox strRec
        Print #aFileNum, strRec
    Next i

    Close #aFileNum

    Set appWord = CreateObject("Word.Application")
    appWord.Documents.Open strMailMergeDocName
    appWord.Visible = True
End Sub
 
Hmmm...I just added some text boxes to a form, named them based on your code..and this worked:

Code:
If strEmployeeID <> intBfPresident Or strEmployeeID <> intBFCADIRECTOR Then
            txtcertificatetype.Value = 3
        
 Else
    txtcertificatetype.Value = 10
End If

I added the Else to make sure the values were changing correctly.
 
Thank you for your help. I will try this tonight.
 
Hmmm...I just added some text boxes to a form, named them based on your code..and this worked:

Code:
If strEmployeeID <> intBfPresident Or strEmployeeID <> intBFCADIRECTOR Then
            txtcertificatetype.Value = 3
 
 Else
    txtcertificatetype.Value = 10
End If

I added the Else to make sure the values were changing correctly.

Doesn't a logical "Or" have higher mathematical precedence than a comparative "<>"? If it does, then adding parenthesis would resolve the issue.
If ((strEmployeeID <> intBfPresident) Or (strEmployeeID <> intBFCADIRECTOR))
 
ok, all of this has been tried and it its still not working.
There must be something else I am missing.

Thank you for your help.
 
Is the code actually executing? I see it's nested inside another conditional statement - are you sure that one is firing OK?

My usual quick-and-dirty way to test this is to insert MsgBox "Banana" immediately before the apparently ineffective line of code.
 
What it does, is it sees if the President was the one teaching the class and if yes, then it pulls the certification merge doc that only has the president's signature. If the teacher and the president are different, then it pulls the cert with 2 signature lines.

They now want to change it so it works they same way for the Director. If the teacher is the director, then pull the 1 signature doc and if different, pull the 2 signature doc.
 
Sounds like you should probably use a Select Case situation.

Select Case strEmployeeID

Case x (x being the ID number of an Employee)
'get the correct whatever
Case y
'get the correct whatever
End Select
 
Hi,

Why dont you go the other way around?

if teacher = president or teacher = director then
1 signatures
else
2 signatures
endif

Simon B.
 
Sounds like you should probably use a Select Case situation.

Select Case strEmployeeID

Case x (x being the ID number of an Employee)
'get the correct whatever
Case y
'get the correct whatever
End Select


Would I just replace the IF stmt with the the case stmt?
 
Yes. The IF statements would go away. Once the code hits the Select Case section, it evaluates the expression (EmployeeID in this case). If it finds a match as defined by the Case, then it will execute the code nested in there.

You can also put a Case Else as the last Case in order to catch any value that isn't specifically defined by it's own case. This way, you only need to include the ID numbers you wish to do something different, and put the default action you want under the Case Else.
 

Users who are viewing this thread

Back
Top Bottom