Multiple Lookup & format change code

sphynx

Registered User.
Local time
Today, 22:57
Joined
Nov 21, 2007
Messages
82
I have written some code to alter the format of a text box when a specific date range is found in the Dlookup. Please bear with me I am relatively inexperienced in VBA!

Private Sub Command590_Click()

W = Now()
Dim X As Date
Dim Y As Integer

X = DLookup("[ISSUE DATE] ", "[MasterWiList_Qry]", "[DESCRIPTION] ='" & [Lvl1Skills_Tbl.1S1] & "'")

Y = Now() - X
Me.Text591.Value = Y

If Me.Text591.Value < 50 Then
Me.Lvl1Skills_Tbl_1S1.ForeColor = 255
Else
Me.Lvl1Skills_Tbl_1S1.ForeColor = 0

End If
End Sub

The code above relates to just one text box, I have approx 30 I need to update in this manner.

I don't want to code every box separately so my question is how do I adjust the code above to loop or cycle through the lookups & Text box references?

Any help will be greatly appreciated
 
you can use a naming convention of somekind to loop through the boxes. something like this:
Code:
dim c as control, i as integer

for each c in me.controls
  if typeof c is textbox then
    c = Now() - DLookup("[ISSUE DATE] ", "[MasterWiList_Qry]", 
      "[DESCRIPTION] ='" & [NAMING CONVENTION TO LOOP THROUGH HERE] & "'")
  end if
next c
 

Users who are viewing this thread

Back
Top Bottom