Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 16th, 2010, 10:17 PM
bph bph is offline
Friend of Wrox
 
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
Default IF ElseIf Compile Error

HI All,

Getting an error with this code. "Complie Error": Else without IF.

Seems straight forward. Thanks for any thoughts. bph

If tblWeekly_Terms.Department Like "Cana*"
Then Set Department = Mid(Department, 10, 50)
ElseIf tblWeekly_Terms.Department Like "FC*"
Then Set Department = Mid(Department, 4, 50)
ElseIf tblWeekly_Terms.Department Like "HEC*"
Then Set Department = Mid(Department, 5, 50)
ElseIf tblWeekly_Terms.Department Like "LC*"
Then Set Department = Mid(Department, 4, 50)
ElseIf tblWeekly_Terms.Department Like "HME*"
Then Set Department = Mid(Department, 5, 50)
ElseIf tblWeekly_Terms.Department Like "Corp*"
Then Set Department = "Corporate"
Else
End If
 
Old September 16th, 2010, 10:53 PM
bph bph is offline
Friend of Wrox
 
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Figured out part of the issue. I cannot put my conditions on the same line as the keywords. I must use the syntax:

If condition Then
statements
ElseIf condition-n Then
elseifstatements
Else
elsestatements
End If

BUT>>>> I get an Object Required Error seming to point at last line.

ElseIf tblWeekly_Terms.Department Like "Corp*" Then
Set Department = "Corporate"

Thoughts? I'll keep hacking away it. Thx. bph
 
Old September 17th, 2010, 09:25 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Yep, one of the object is null...
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old August 13th, 2013, 12:10 PM
Registered User
 
Join Date: Aug 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Does your code also include a select...case statement?

I've found that if you've omitted the End Select statement, your if..else..endif loops will throw up this error.





Similar Threads
Thread Thread Starter Forum Replies Last Post
compile error yogeshyl Excel VBA 0 December 12th, 2007 06:41 AM
ElseIF dhoward VB.NET 2002/2003 Basics 4 July 5th, 2007 12:57 PM
Compile error: Syntax error: & Else without HELP Corey VB How-To 2 April 21st, 2006 03:25 PM
If then Elseif systax error alisonchase ASP.NET 1.0 and 1.1 Basics 3 January 30th, 2005 07:50 AM
Compile Error: Michael Gavel BOOK: Beginning Access VBA 2 January 20th, 2004 11:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.