Topic: VBA Code in Access | |
---|---|
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 |
|
|
|
Are you OK this morning?
|
|
|
|
Is it morning? I have been up all night working on this dumb database...
|
|
|
|
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 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 I think you want to use an ElseIf, if I'm understanding the question. |
|
|
|
Edited by
someguy1313
on
Mon 11/10/08 07:31 AM
|
|
got it thanks
|
|
|
|
Or you could use CASE...
|
|
|
|
Or you could use CASE... He cannot use CASE, IF/Then logic is the way to go. There are AND clauses, which couldn't be included with a CASE. |
|
|
|
My VBA is very rusty, but it looks like he's already using ElseIf.
|
|
|
|
Or you could use CASE... He cannot use CASE, IF/Then logic is the way to go. There are AND clauses, which couldn't be included with a CASE. Ever hear of nesting? |
|
|
|
Or you could use CASE... He cannot use CASE, IF/Then logic is the way to go. There are AND clauses, which couldn't be included with a CASE. Ever hear of nesting? Yes, I have. Did you notice that he has 9 different AND clauses? ElseIf would be much more efficient and easier to read than a 12 Case statement with multiple sub IF/CASE statements. |
|
|