Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If Like then ElseIf

Status
Not open for further replies.

Zeroanarchy

Technical User
Jun 11, 2001
630
AU
Hey just a little stuck,

Can anyone help with this:

Code:
If pcktype Like "*Ambulance*" Then XV = "Ambulance"
ElseIf pcktype Like "*Car*" Then XV = "Car"
ElseIf ......

I am unable to get this to work due to Access not reconising the first If, I keep getting "ElseIf without If" Error.

Cheers

[afro]ZeroAnarchy
Experience is a wonderful thing. It enables you to recognize a mistake
when you make it again.

 
When Access VBA sees the Then statement on the same line as the If statement it assumes that there is no Else and doesn't require an End If:

If a = b then c

Try moving the statement after each Then clause to a new line:

If pcktype Like "*Ambulance*" Then
XV = "Ambulance"
ElseIf pcktype Like "*Car*" Then
XV = "Car"
ElseIf ......

Remember an End If at the end of the entire If clause!

[shadeshappy] Cruising the Information Superhighway at the speed of light
[sub] (your mileage may vary)[/sub]
 

Depending on the number of ElseIf's you'll have, you might consider using a SELECT statement instead.
Code:
SELECT Case pcktype
    Case Like "*Ambulance*":
        XV = "Ambulance"
    Case Like "*Car*":
        XV = "Car"
End Select


Randy
 
Isn't it interesting, I have written some really large programs in Access and I have worked on stacks of programs and still the most obvious things don't register at the time you are working on the code.

Thanks wemeier and randy700 for you help.

Cheers


[afro]ZeroAnarchy
Experience is a wonderful thing. It enables you to recognize a mistake
when you make it again.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top