array problem

arage

Registered User.
Local time
Today, 09:21
Joined
Dec 30, 2000
Messages
537
array problem
I’m trying to use/learn arrays & am using one in a standard code module so that a particular array index can stand in for the name of a string, that is meant to lock out a control on a form.

Below code shows declarations and assignment of the of array index in the standard code module & followed by that is the procedure meant to lock out the controls on the form. This procedure (lockTaxes) is not recognizing my array index as a valid reference to a control, could someone help out please?

Public aryTax(7) As String 'assign an array to hold taxes to be locked...
Public Code As Variant 'holds a code...
Public sysTyp As String 'holds 'OA' or 'BE'....

'determines the tax controls to lock on promoPreAapproval/Cpr tab...
Public Function lockTaxes2()

'determine taxes to lock...
Select Case Code
Case "1499"
'has GST,PST,QST open...
aryTax(0) = "ForecastHST"
aryTax(1) = "ActualHST"
Case "1599"
'has HST open
aryTax(0) = "ForecastGST"
aryTax(1) = "ForecastPST"
aryTax(2) = "ForecastQST"
aryTax(3) = "ActualGST"
aryTax(4) = "ActualPST"
aryTax(5) = "ActualQST"
End Select

'locks tax controls...
Public Sub lockTaxes(Code, sysTyp)

'determines which tax controls to lock...
Call lockTaxes2

'lock taxes returned by lockTaxes2()...
Dim intI As Integer

For intI = 0 To 7
If sysTyp = "OA" Then
Forms!NewDataEntry!aryTax(intI).Locked
Else
Forms!BackEndDataEntry!aryTax(intI).Locked
End If

Next intI
End Sub
 
Try this format when referencing the controls with your string array:

Instead of:
Forms!NewDataEntry!aryTax(intI).Locked

use:
Form_NewDataEntry.Controls(aryTax(intI).Locked
 
Sorry, forgot a ")"

Form_NewDataEntry.Controls(aryTax(intI)).Locked
 
you're telling me, don't worry i caught it
smile.gif
i'll post shortly, lockTaxes2 is acting up since the indexes contain strings and but the array is returned as a control.
 
lockTaxes2 is saying an invalid use of property I’m assigning a string value to an array defined as a controls but I don’t know how else to initialize the index with the NAME of the applicable control.
 
1. You need to set the Locked Property = to something (True/False)

2. Your loop will go through 8 times (0 to 7) in both of your cases you will end up with an Empty String for a control name.

3. You Have Public variables that are the same name as your passed variables. While this is not a problem, in your case you are not setting the Public variables Code and sysTyp.


Look at using the following to make life easier with arrays:

Split
Ubound
Lbound
 
Travis,

your point 2 is what has been driving me up the wall.

point 3, those public vars defined at the start are the ones used in the modules procedures/functions, so i don't have to create the same values for each sub/func in the module.
 
well, I’ve modified my code some but am getting an invalid use of property on the assignment of my array index to a control, what am I missing since I’ve defined the array as a control to begin with? I would have liked to have assigned the controls as it appears in my commented out code but am trying using the entire form path to define it for now.

'determines the tax controls to lock on promoPreAapproval/Cpr tab...
Public Function lockTaxes2(sysTyp)

If sysTyp = "OA" Then
'determine taxes to lock...
Select Case Code
Case "1299"
'has GST & PST open...
aryTax(0) = Form_NewDataEntry.ForecastQST
aryTax(1) = Form_NewDataEntry.Controls(ForecastHST)
' aryTax(2) = ActualQST
' aryTax(3) = ActualHST
' Case 1599
' 'has HST open
' aryTax(0) = ForecastGST
' aryTax(1) = ForecastPST
' aryTax(2) = ForecastQST
' aryTax(3) = ActualGST
' aryTax(4) = ActualPST
' aryTax(5) = ActualQST
End Select
End If
End Function
 
Did you look up Split, lBound and uBound to see how they work?

You can Define your array at the time of population vice the time of Creation.

Public aryTax()

Then use the Split to set your array.

aryTax=Split("ForecastHST,ActualHST",",")

Then use a For...Next Loop using the lBound and uBound to tell you the start and end of an array

For x=lBound(aryTax) to uBound(aryTax)
'code to set your form fields
Next x
 
Travis I don’t find any help in access97 for Split, where do I look to find it?
 
If split is not available try declaring the size just before you populate it:

ReDim aryTax(1) 'Creates aryTax(0) and aryTax(1)

That way you can still use lBound and uBound to get your dimesions for the loop.
 

Users who are viewing this thread

Back
Top Bottom