Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Missing Library

Status
Not open for further replies.

irishandy

Programmer
Nov 18, 2003
39
IE
Hi.

I've made a copy of an Access 2.0 database and converted it to Access 97. A particular report now refuses to run - the offending lines are the following...

ReDim Preserve li_PAmount(li_POS) As Double
ReDim Preserve li_AAmount(li_POS) As Double

...and further down...

li_PAmount(li_POS) = 0
li_AAmount(li_POS) = 0

When I try to run the report, it dumps me into code with the error: "Compile Error: Variable not defined". When I comment out the particular lines, the report runs however I'm concerned that something will potentially go wrong in the future. After all, those lines are there for a reason!

I assume I'm missing a library - how do I fix this?
 
You are working with an array. Somwhere there is a Dim statement that should look like this:

Dim li_AAmount() As ????
Dim li_PAmount() As ????

li_PAmount(li_POS) = 0 apparently stores the value 0 in the li_POSth position of the array. This would only work if the Type statement has only a single variable defined in the content.

The 'As' statements will refer to a 'Type' which has declared the structure of the array. You are not missing a library. See the example below.

Type myArray
Name As String
Address As String
City As String
End Type
Dim myArrayVariable As myArray

Here is where I would start. The ReDim statement you have does not comform sytactically with the ReDim statement. You could go to help and search for Redim. If you look at the example above the Type statement says what the contents include so try replacing:

ReDim Preserve li_PAmount(li_POS) As Double
with
ReDim Preserve li_PAmount(li_POS)








---------------------
scking@arinc.com
---------------------
 
Thanks for your reply. I've searched the database code for all instances of li_PAmount and nowhere is there a statement similar to

Dim li_PAmount As ...

It's ReDim Preserve every time. There does exist however "Dim ld_PAmount As Double".

I also tried replacing the line with your version, i.e. deleting the "As Double". This produced the same error message.

Why would it be a syntactic error if it works fine in Access 2.0?
 
Why would it be a syntactic error if it works fine in Access 2.0?
-----------------------------
Now that's a good question. I've worked with Access since 1.0 and there have been a number of enhancements since them. Maybe one was to the compiler.

Here's my take on this.

Dim ld_PAmount As Double (This is correct as stated. It correctly dimensions a single variable as a double.)

ReDim Preserve li_PAmount(li_POS) As Double (This is hosed. It is incorrectly trying to ReDim a single variable which is not described as an array. The li_POS counter in the structures states which index in the array to use. The As Double seems to show a misunderstanding about the purpose of the ReDim keyword.

li_PAmount(li_POS) = 0 (This is hosed unless it is dimensioned as an array, and, as you said, it isn't)

I use array constructs very very much. My current app has 15,000 lines of VBA code divided between Access, Excel, and Microsoft Project, and a lot of that code uses arrays. This seems to me developed by someone confused about arrays, and the ReDim statement. We have all been confused about Access at one time or other. My first generation of applications was simple and full of defects. After 10 years of developing in Access I know more that when I started.

Recommendation is to comment out all ReDims and change the assignments to assign to the variable (li_PAmount = 0).







---------------------
scking@arinc.com
---------------------
 
At the beginning of your procedure you should have something like this:
Dim li_PAmount() As Double
Dim li_AAmount() As Double
In your code, the ReDim should be like this:
ReDim Preserve li_PAmount(li_POS)
ReDim Preserve li_AAmount(li_POS)

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
I was wondering why the line "Dim ld_PAmount As Double" was included at all, as there is no other reference to ld_PAmount anywhere in the database. I changed the line to refer to "li_PAmount" instead and got rid of the "As Double" from the ReDim lines. It now seems to work fine, though I'd still be interested as to why it worked in 2.0.

I now have:

Dim li_PAmount As Double
Dim li_AAmount As Double
...
ReDim Preserve li_PotAmount(li_POS)
ReDim Preserve li_ActAmount(li_POS)
...
li_PotAmount(li_POS) = 0
li_ActAmount(li_POS) = 0


Thanks schking and PHV for your helpful replies.
 
irishandy

If the compiler doesn't beep for that I don't know why. The Dim statement isn't for an array. I've pasted the help for the ReDim statement below. The entire purpose of ReDim is to allocate space in an array. For instance, if you have one record in the array filled it would be the 0 index. To add another record to the array and save the previous contents stored in index 0 you would ReDim to create the new record and Preserve to retain the previous array data; so ReDim Preserve li_PotAmount(1) would save the first record and add a new record so you could then reference the array elements for the new record. According the the above li_PotAmount(li_POS) = 0 should cause the compiler to beep. Maybe not if li_POS is only 0 if the Option Base is not set to 1.

PHV showed the Dim statement as an array so all the following statements are for array handling and would work perfectly.

ReDim Statement Example
This example uses the ReDim statement to allocate and reallocate storage space for dynamic-array variables. It assumes the Option Base is 1.

Dim MyArray() As Integer ' Declare dynamic array.
Redim MyArray(5) ' Allocate 5 elements.
For I = 1 To 5 ' Loop 5 times.
MyArray(I) = I ' Initialize array.
Next I



---------------------
scking@arinc.com
---------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top