Avatar of Clive Beaton
Clive Beaton
Flag for Australia asked on

Left function - 'Expected Array'

Can anyone help me with this compiler error?  I use the Left function elsewhere in a different module which doesn't raise this error.

Thanks in advance
Microsoft Access

Avatar of undefined
Last Comment

8/22/2022 - Mon

Try to use Left$ instead of Left

Left$ is equivalent to Left (but obsolete)

Your syntax for Left is fine.

You may want to Dim s1 and s2 on seperate lines of code.  I've seen other posts around here saying that despite the 'As String', the second string will actually get defined as a Variant.

    Dim s1 As String
    Dim s2 As String
    s2 = "abc"
    s1 = Left(s2, 1)
    MsgBox s1

Open in new window

That in itself, however shouldnt cause this error.  Your code looks good and works fine for me.

In the VBA editor, check tools --> references.  If any are labeled as MISSING, uncheck them and replace them with the correct version.
Clive Beaton

Done that.  Different error.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Clive Beaton


Did a Compact & Repair.  Changed back to Left.  Separated the Dim statements.  Still got 'Expected array'

No missing references.

Tried it in an earlier version of the program and it worked fine.  The references were identical as well.

Where from here, I wonder.

Is s2 defined anywhere else in this module?

Have you posted your full and complete code, or have you abbreviated it for the purpose of making a concise forum post?  (We'd need to see the full code)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Clive Beaton

S2 only appears in commented out code.

Full code attached.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.

The code compiled OK on my side. Please check the references in your project. If you have a wrong reference (look for "Missing" word on checked references) this is the behaviour

Try decompiling, and also give this a try:

Public Sub ConvertPostcodes()

   Dim rs As Recordset
   Dim i As Long
   Dim s1 As String
   Dim s2 As String
   Dim Mystr As String

   Set rs = CurrentDb.OpenRecordset("tblPostcodes", dbOpenDynaset)

   s2 = ""
   With rs
      If Not .EOF Then
         Do Until .EOF
            s1 = !Locality
            Do Until Len(s1) = 0
              s2 = s2 & Left(s1, 1)
               s1 = Mid(s1, 2)
               i = InStr(s1, " ")
               If i = 0 Then
                  s2 = s2 & s1
                  s2 = s2 & Mid(s1, i - 1)
                  s1 = Mid(s1, i + 1)
               End If
            Debug.Print s2
'            .Edit
'               !Locality = s2
'            .Update
      End If
   End With
End Sub 

Open in new window

Can you describe what you are trying to do?  there may be a better approach.
Clive Beaton

Tried different variable names.

Haven't used Left as a variable or global name.

Read Jim Dettmans article.


Imported everything into a brand new database.

Created a new module, copied all the code into it (ctl/C Ctl/V), deleted the old module. and compiled.

Still get same error.

Interesting thing is, Left compiles and works in other modules, so I moved the function to another module and it compiled.

So at least I can move on.  Your help has been worth the points.  It put me on the right track.  

I'm going it have to re-visit this because it worries me, so more questions on this will be coming soon..
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Clive Beaton

See my final comments.
Clive Beaton

In answer to your question about what I want to do is take a name like
and convert it into
Australian National University.
Ken Butters

I ran into a similar problem recently.

Since this was posted under Access 2010, I am assuming that you are using the function in VBA.

When you have a lot of references... sometimes you inadvertently pull in another reference to "left" or "right" and your appliction can get confused.   In this case if you fully qualify your function call... it will help your application understand which function it should use.

All of the following are equivalent... and one of the more fully qualified calls might work for you.
Sub test()
    y = "Test"

    x = Left(y, 1)
    x = Strings.Left(y, 1)
    x = VBA.Strings.Left(y, 1)
End Sub

Open in new window

looking through VBA's object browser will help you determine what the "fully qualifed" names are that you should use for any given function.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.

Your code could be simplified alot by converting to Proper case like this:

Newstring =  strconv(s,vbProperCase)

>> I'm going it have to re-visit this because it worries me

Agreed... If you can post a sample database (just scrub it of any sensitive data first), lets keep working at it.
Clive Beaton


You're worth your weight in gold.  Thanks very much.  I'll be back in touch.

Your help has saved me hundreds of hours of internet surfing.

If you haven't already, you should try the comment by buttersk at http:#a38007536, and put the vba prefix in front of Left.

However, since Left is a built in VBA function, unless something is slightly amiss in your database, left should work properly without the prefix (it should take priority over Left in other libraries).

Also check one more time for Left defined implicitly or explicitly as a function or variable anywhere within this module of code (or in your database).

Btw - if you use the Request Attention button, a Moderator can reopen this for you.  Its best  to just have solutions that work marked as the answers, since others in the same situation refer to these threads for solutions.