473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Compile Error: Expected Array

I have code built into a form in Access and everytime I try to open the form it gives me a Compile error: Expected array message and then highlights the word Left. I did not create this program and know very little about VBA but have been given the responsibility to take over this program. Please help I'm desperate!

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer) 'Added
  2.     'unlock fields for STL
  3.     If TempVars![tvIsSTL] And Status <> "Closed" And Status <> "Historical" Then
  4.         Dim c As control
  5.         For Each c In Me.Controls
  6.             If Left(c.Name, 3) = "STL" Then
  7.                 Select Case c.ControlType
  8.                     Case Is = acTextBox
  9.                         c.Locked = False
  10.                     Case Is = acListBox
  11.                         c.Locked = False
  12.                     Case Is = acComboBox
  13.                         c.Locked = False
  14.                     Case Is = acCheckBox
  15.                         c.Locked = False
  16.                     Case Is = acCommandButton
  17.                         c.Enabled = True
  18.                 End Select
  19.                 If Left(c.Name, 4) = "STLO" Then c.Visible = True
  20.                 If InStr(1, UCase(c.Name), "CLOSEPROJECT") > 0 Then c.Visible = True
  21.             End If
  22.         Next
  23.     End If
Feb 14 '11 #1
4 8428
Stewart Ross
2,545 Expert Mod 2GB
There is nothing wrong with the use of Left in the code segment above. Left returns the leftmost-N characters from a string, where N is the second argument in the call in each case. Left definitely does not take an array argument!

This type of error - where common built-in functions such as Left stop working - occurs either when there are errors in the database, or, more commonly, when upgrades leave problems with access to code libraries. First step would be to do a compact and repair on the database. If that fails, you need to check the library references. This article on Allen Browne's web site gives further details on how to do this: http://allenbrowne.com/ser-38.html

-Stewart
Feb 14 '11 #2
Thank you for your input. I found the solution not long after I posted this. The word Left had been defined elsewhere in the code so I added VBA.Left to this code and the error went away.
Feb 15 '11 #3
Stewart Ross
2,545 Expert Mod 2GB
Ahh. Hadn't thought of the possibility of redefining a standard keyword in VBA to mean something else...

One of the useful naming conventions which can be adopted is to prefix user-written functions with the letter f (for Function) to make it clear that the function is user-defined and not built-in. In this case it would have the benefit of not being named the same as a standard function. The function header would be something like

Expand|Select|Wrap|Line Numbers
  1. Public Function fLeft(SomeArguments) as SomeType
  2.   .
  3.   .
  4.   fLeft = SomeValue
  5. End Function
Something to consider for the future?

-Stewart
Feb 15 '11 #4
I agree, that's not a bad idea.
Feb 15 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: wwwursa | last post by:
I am trying to use the Right function in a VB6 program. I have used it used many times before in other programs. When I press the enter key after entering the code line, the word "Right" turns...
5
by: iheartvba | last post by:
Hi Everyone, I keep on getting an error saying Compile Error: Expected Case in my (MS Access) VBA What I was trying to do was to do a DSUM function for a Table where the criteria was coming from...
1
by: darrel | last post by:
Hello, i need you help, can someone whats the cause of getting an error of Expected function or variable, its like this i have a function code in a module and call it on my main form.. here my code:...
1
by: kieran04 | last post by:
every time i run this program in VBE i keep getting the message 'Compile Error: expected array' for the two bold lines underneath, please help? Public Function KnotsToKmPerHr(knots As...
2
by: rocky102 | last post by:
I am a novice old timer who enjoys fooling around with excel, I copied this macro from and old computer and wanted to use it one a new one I got. Its supposed to draw a line across a row when...
1
by: Dorota Prywata | last post by:
Hi, I need help with VBA Macro for Auto-filter to high lite a header plp advice as per below course a I got Compile error: Expected End Sub ? Sub Macro1() Function FilterOn(myCell As Range)...
2
by: engrlorie | last post by:
I am a newbie in programing and is currently designing a program using VB6 with access 03 database. Unfortunately, I am stuck with the error. Please help me.. can't decipher the problem myself....
10
by: JEFFREY MUSGRAY | last post by:
I have received alot of help from this site and I am grateful. My problem is that I was able to get the first part of code to work. I tested it via the immediate window. I received the compile error...
2
by: Emmanuel Ayivi | last post by:
I have a database in which there is a table named as tblfeesdetails. In this table the following fields exist; groupid, Academic_year, Term, Tdate, Debit and credit. Now I need to select from the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.