473,586 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Compile Error: Expected Array

3 New Member
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 8451
Stewart Ross
2,545 Recognized Expert Moderator Specialist
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
Lindsay Bradley
3 New Member
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 Recognized Expert Moderator Specialist
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
Lindsay Bradley
3 New Member
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
5416
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 into "RIGHT" in all capital letters The line is LongText = RIGHT(LongText, 2) I have used Option Explicit to make sure all variables are...
5
15175
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 another table, I later found the criteria needs to be from within the domain table I had set DSUM function (makes sense). I then when to Query Bulder to...
1
8999
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: Function DTR7() Dim rs As New ADODB.Recordset Dim cnn As New ADODB.Connection Dim x As Integer frmMain.Command2.Visible = True ...
1
5143
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 Double) As Double Dim Km As Double KNOTS_TO_KM = 1.852 Km = knots * KNOTS_TO_KM KnotsToKmPerHr = Km
2
16416
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 there is a change from one number to another. When I try to use it I get this error Compile Error Expected End Sub Help please.
1
15094
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) As Boolean On Error Resume Next With myCell.Parent.AutoFilter With .Filters(myCell.Column - .Range.Column + 1)
2
6548
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. Scenario is I have 4 tables (lightinfo, location, characteristics, and pics). They are connected through National ID from lightinfo. strQuery =...
10
8587
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 "expected expression" when I tested for function InputFile. ?InputFile(Optional strPath As String) "expected expression" ?InputFile()...
2
4531
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 above table base of two (2) criteria into a diferent table called tblfeestrans where Tdate is maximum but anytime I run the query below an error occurs...
0
7839
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8200
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7954
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8215
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3836
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.