Compile error: Expected =

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This code is intended to evaluate a variable called OType. If this variable
is NOT null, then the statements in the Select Case section should run:

Public Function OGroup(OType As Variant, OClass As String)

OrclClass = Left(OClass, 6)

If Not IsNull(OType) Then

Select Case OrclClass
Case 100000 To 199999
OGroup = "ASSETS"
Case 200000 To 270000
OGroup = "LIABILITIES"
Case 280000 To 299999
OGroup = "EQUITY"
Case 347000 To 399000
OGroup = "SALES"
Case 447000 To 480000
OGroup = "COS"
Case 600000 To 948000
OGroup = "EXPENSES"
Case Else
OGroup = "UNCLASSIFIED"
End Select

Else

Debug.Print "It Doesn't Work"

End If

End Function

I'm getting the error message displayed above when I run this function. Any
ideas?
 
Kirk,

The ecpression Left(OClass, 6) returns a string, so OrclClass is
assigned a string value, whereare your Case statemens are built for a
numeric one, so you have a type mismatch. To overcome this, change the
first line to:

OrclClass = Val(Left(OClass, 6))

so OrclClass is assigned a numerical value which can be evaluated
correctly in the existing Select structure.

Besides that, the way your If Then Else is structured, the Debug.Print
will be executed if OType is null; was that the intention?

HTH,
Nikos
 
Which line of code Access highlights as the line with the Compile error?

From what I see in your code, OrclClass is a Variant of String type but in
the Select Case statement, you compare it with numeric values. Access may
or may not handle the type-casting correctly for you.

BTW, I can't see the declaration for OrclClass. It is recommended that you
use the "Option Explicit" in all code modules. This helps you to detect
undeclared variables which are often the results of typing mistakes.
 
Back
Top