using a variable to refer to a form element name

RobJen

Registered User.
Local time
Today, 20:25
Joined
Jul 19, 2005
Messages
35
Hi, I am lost in this problem where I dont seem to be able to find the answer, it should be relatively simple though:

Code:
Dim mytimer As Integer
Dim test
test = Me.DentalDatum
mytimer = 180

If test < (Now - mytimer) Or IsNull(test.Value) Then test.BackColor = "255" Else test.BackColor = "-2147483643"

The thing is I would like to refer to a form element by using a VBA variable. Can someone point me in the right direction? Thanks in advance.

Rob
 
ugh never mind, I am such a rookie lol, I forgot to set the variable...so it works now :)
 
but now I am trying this with an array and this still gives me troubles, here is a part of the code:

Code:
Dim array1 As Variant, mytime As Integer, field, i

array1 = Array("DentalDatum", "HepB")
mytime = 180

i = 0
For Each field In array1
field = Me.array1(i)

i = i + 1
Next
 
sorry dont like to top my own messages but I feared my question got missed because I initially found the solution
 
I am not sure what you are trying to do.
Array1 will just be a list of text field names
if you want to loop through them you would need something like
for i = 0 to ubound(array1)
xyz = Me.Controls(array1(i))
next i

HTH

Peter
 

Users who are viewing this thread

Back
Top Bottom