Hi, I am initializing some controls on a form, I have a set of edit boxes named edtDBH1, edtDBH2...edtDBH6.
The user selects the number of items to be recorded and my script is supposed to enable the right number of controls and disable the others. To do this I am using a For loop to call a function with parameters for: control to be changed, iteration number and the Boolean value. This way I can recycle the function and use it to disable the remaining controls by using a countdown loop with Boolean value set to false.
The first loop works fine but the second loop does it's job and then throws a VBScript error: Object Required: rfPage...
I think I am not closing the first loop correctly or somehow the first loop is messing with the object references established at the start.
Any suggestions?
Code:
Sub SetNumDBH
Dim objPg, numDBH, controlCount
Set objPg = Layers("Tree_Inventory").Forms("EDITFORM").Pages("pgDBH").Controls
numDBH = objPg("cboNumDBH").Value
if numDBH = 0 then
MsgBox "DBH Number Not Valid! Check Values!"
Exit Sub
End If
For controlCount=1 to numDBH
call changeEDT(objPg, controlCount, True)
Next
For controlCount = (numDBH+1) to 6
call changeEDT(objPg, controlCount, False)
Next
End Sub
Function changeEDT(byRef rfPage, counter, boolVal)
Dim strEdtName
strEdtName = "edtDBH" & counter
'MsgBox "Called: bool: " & boolval & " string:" & strEdtName
rfPage(strEdtName).Enabled = boolval
rfPage(strEdtName).Visible = boolval
End Function
-----------------------------------------------------------------------------------------
Many Thanks
Dennis