better
09-01-2006, 06:14 AM
Is there a way that I can store objects, not their values, in an array, and then process them using array syntax? I'm thinking of something along these lines...
Private Sub UpdateControls(Exists as Boolean)
Dim CtrlArr(2, 2) as Variant
Dim I as Integer
Dim rs as Object
Set rs = CurrentDb.OpenRecordset ("ContactInfo")
CtrlArr(0, 0) = Me![Customer]
CtrlArr(0, 1) = Me![Address]
CtrlArr(0, 2) = Me![Phone]
CtrlArr(1, 0) = rs(0)
CtrlArr(1, 1) = rs(1)
CtrlArr(1, 2) = rs(2)
CtrlArr(2, 0) = ""
For I=0 to UBound CtrlArr(0,1)
If Exists = True Then
CtrlArr(0, I) = CtrlArr(1, I)
Else
CtrlArr(0, I) = CtrlArr(2, 0)
End If
Next
End Sub
This is obviously somewhat simplified. There are 33 form fields that I need to either update or clear conditionally, and I don't want to code for each one seperately. How can I do this?
Thanks in advance!
Bart
Private Sub UpdateControls(Exists as Boolean)
Dim CtrlArr(2, 2) as Variant
Dim I as Integer
Dim rs as Object
Set rs = CurrentDb.OpenRecordset ("ContactInfo")
CtrlArr(0, 0) = Me![Customer]
CtrlArr(0, 1) = Me![Address]
CtrlArr(0, 2) = Me![Phone]
CtrlArr(1, 0) = rs(0)
CtrlArr(1, 1) = rs(1)
CtrlArr(1, 2) = rs(2)
CtrlArr(2, 0) = ""
For I=0 to UBound CtrlArr(0,1)
If Exists = True Then
CtrlArr(0, I) = CtrlArr(1, I)
Else
CtrlArr(0, I) = CtrlArr(2, 0)
End If
Next
End Sub
This is obviously somewhat simplified. There are 33 form fields that I need to either update or clear conditionally, and I don't want to code for each one seperately. How can I do this?
Thanks in advance!
Bart