Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


VBA / ACCESS Question


VBA / ACCESS Question

Author
Message
SomeGuy1313
SomeGuy1313
Forum God
Forum God (444 reputation)Forum God (444 reputation)Forum God (444 reputation)Forum God (444 reputation)Forum God (444 reputation)Forum God (444 reputation)Forum God (444 reputation)Forum God (444 reputation)Forum God (444 reputation)

Group: Forum Members
Posts: 2, Visits: 4
I am new to VBA does anyone know how this SHOULD have been written... I know every IF needs an END IF and the word OR does not seem to work so how would I cover all the below... and writing an IF for each does not work.

Private Sub cmbInternalStatus_Exit(Cancel As Integer)

If cmbInternalStatus = "Approved" And cmbWebStatus = "Approved" Then
     Cancel = False
If cmbInternalStatus = "Closed (Other)" And cmbWebStatus = "Closed (Other)" Then
     Cancel = False
If cmbInternalStatus = "Director Review" And cmbWebStatus = "Functional Analysis" Then
     Cancel = False
If cmbInternalStatus = "Disapproved" And cmbWebStatus = "Disapproved" Then
     Cancel = False
If cmbInternalStatus = "Functional Analysis" And cmbWebStatus = "Functional Analysis" Then
     Cancel = False
If cmbInternalStatus = "Fwd for Cmd Analysis" And cmbWebStatus = "Fwd for Cmd Analysis" Then
     Cancel = False
If cmbInternalStatus = "Fwd for Decision" And cmbWebStatus = "Fwd for Decision" Then
     Cancel = False
If cmbInternalStatus = "Fwd to SME" And cmbWebStatus = "Fwd to SME" Then
     Cancel = False
If cmbInternalStatus = "Ineligible" And cmbWebStatus = "Ineligible" Then
     Cancel = False
If cmbInternalStatus = "Pending Payment" And cmbWebStatus = "Approved" Then
     Cancel = False
If cmbInternalStatus = "Staffing (TL Only)" And cmbWebStatus = "Approved" Then
     Cancel = False
If cmbInternalStatus = "Team Lead Review" And cmbWebStatus = "Functional Analysis" Then
     Cancel = False
If cmbInternalStatus = "Tech Review" And cmbWebStatus = "Functional Analysis" Then
     Cancel = False
Else
    MsgBox "Internal Status does not match Web Status, please correct.", , "Silly Analyst!"
     Cancel = True
End If
   
End Sub

AKGrown
AKGrown
Supreme Being
Supreme Being (279 reputation)Supreme Being (279 reputation)Supreme Being (279 reputation)Supreme Being (279 reputation)Supreme Being (279 reputation)Supreme Being (279 reputation)Supreme Being (279 reputation)Supreme Being (279 reputation)Supreme Being (279 reputation)

Group: Forum Members
Posts: 1, Visits: 44
You either need to if.....end if at every statement or if.....elseif....if......elseif then a final end if after the last if statement.
system.authorizing
system.authorizing
Supreme Being
Supreme Being (277 reputation)Supreme Being (277 reputation)Supreme Being (277 reputation)Supreme Being (277 reputation)Supreme Being (277 reputation)Supreme Being (277 reputation)Supreme Being (277 reputation)Supreme Being (277 reputation)Supreme Being (277 reputation)

Group: Forum Members
Posts: 1, Visits: 13
use your code like this :-

Private Sub cmbInternalStatus_Exit(Cancel As Integer)

If cmbInternalStatus = "Approved" And cmbWebStatus = "Approved" Then
     Cancel = False
ElseIf cmbInternalStatus = "Closed (Other)" And cmbWebStatus = "Closed (Other)" Then
     Cancel = False
ElseIf cmbInternalStatus = "Director Review" And cmbWebStatus = "Functional Analysis" _Then
     Cancel = False
ElseIf cmbInternalStatus = "Disapproved" And cmbWebStatus = "Disapproved" Then
     Cancel = False
ElseIf cmbInternalStatus = "Functional Analysis" And cmbWebStatus = "Functional Analysis" Then
     Cancel = False
ElseIf cmbInternalStatus = "Fwd for Cmd Analysis" And cmbWebStatus = "Fwd for Cmd Analysis" Then
     Cancel = False
ElseIf cmbInternalStatus = "Fwd for Decision" And cmbWebStatus = "Fwd for Decision" Then
     Cancel = False
ElseIf cmbInternalStatus = "Fwd to SME" And cmbWebStatus = "Fwd to SME" Then
     Cancel = False
ElseIf cmbInternalStatus = "Ineligible" And cmbWebStatus = "Ineligible" Then
     Cancel = False
ElseIf cmbInternalStatus = "Pending Payment" And cmbWebStatus = "Approved" Then
     Cancel = False
ElseIf cmbInternalStatus = "Staffing (TL Only)" And cmbWebStatus = "Approved" Then
     Cancel = False
ElseIf cmbInternalStatus = "Team Lead Review" And cmbWebStatus = "Functional Analysis" Then
     Cancel = False
ElseIf cmbInternalStatus = "Tech Review" And cmbWebStatus = "Functional Analysis" Then
     Cancel = False
Else
    MsgBox "Internal Status does not match Web Status, please correct.", , "Silly Analyst!"
     Cancel = True
End If
   
End Sub

ABBA JEE

Mark
Mark
Forum God
Forum God (144K reputation)

Group: Moderators
Posts: 1.1K, Visits: 11K
You may want to try a Select Case
Private Sub cmbInternalStatus_Exit(Cancel As Integer)

    Select Case True
        Case cmbWebStatus = "Functional Analysis" And ( _
            cmbInternalStatus = "Director Review" Or _
            cmbInternalStatus = "Functional Analysis" Or _
            cmbInternalStatus = "Team Lead Review" Or _
            cmbInternalStatus = "Tech Review")
            Cancel = False
        Case cmbWebStatus = "Approved" And ( _
            cmbInternalStatus = "Pending Payment" Or _
            cmbInternalStatus = "Staffing (TL Only)" Or _
            cmbInternalStatus = "Approved")
            Cancel = False
        Case cmbInternalStatus = "Closed (Other)" And cmbWebStatus = "Closed (Other)"
            Cancel = False
        Case cmbInternalStatus = "Disapproved" And cmbWebStatus = "Disapproved"
            Cancel = False
        Case cmbInternalStatus = "Fwd for Cmd Analysis" And cmbWebStatus = "Fwd for Cmd Analysis"
            Cancel = False
        Case cmbInternalStatus = "Fwd for Decision" And cmbWebStatus = "Fwd for Decision"
            Cancel = False
        Case cmbInternalStatus = "Fwd to SME" And cmbWebStatus = "Fwd to SME"
            Cancel = False
        Case cmbInternalStatus = "Ineligible" And cmbWebStatus = "Ineligible"
            Cancel = False
        Case Else
            MsgBox "Internal Status does not match Web Status, please correct.", , "Silly Analyst!"
            Cancel = True
        End Select
    
End Sub

Edit: I guess I should have looked at the date of the OP.

Edited
2/10/2009 by Mark
GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search