change backcolor of multiple controls in loop

alaric

Registered User.
Local time
Today, 15:35
Joined
Sep 6, 2004
Messages
50
I just cant get it figured out. It's driving me crazy. Can someone help me or am I trying to do something impossible??

I have a for with multiple subforms (all equal)
When I hit the save button the procedure should check all 8 fields (txtPunt1 through 8) for empty fields. All empty fields should get a red backcolor until all values are typed into the fields.
I try to do this with following code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
'Check on empty fields

Dim Counter, check
Counter = 1: check = True
Dim strPuntVeld As String

Do
Do While Counter < 7
strPuntVeld = "Form_SFAfdansen1.txtPunt" & Counter
If IsNull(strPuntVeld & ".Value") = True Then
Else
Counter = Counter + 1
End If
If Counter = 6 Or IsNull(strPuntVeld & ".Value") = True Then
check = False
MsgBox "Vul alle punten in. ", vbExclamation + vbOKOnly, ConAppName
Cancel = True
If IsNull(strPuntVeld & ".Value") = True Then
Forms("SFAfdansen1").Controls("txtPunt" & Counter).BackColor = 255
Else
Forms("SFAfdansen1").Controls("txtPunt" & Counter).BackColor = -2147483643
End If
Exit Do
End If
Loop
Loop Until check = False

end sub

It seems that the code doesnt understand the variable in the control. But I cant think of another solution

please help
Alaric
 
Last edited:
alaric,

Code:
Dim i As Integer
Dim IsOkay As Boolean

IsOkay = True
For i = 1 To 8
   If IsNull(Me.Controls("txtPunt" & i) Then
      Me.Controls("txtPunt" & I).BackColor = 255
      IsOkay = False
   Else
      Me.Controls("txtPunt" & I).BackColor = -2147483643
   End If
   Next i
If Not IsOkay Then
   MsgBox "Vul alle punten in. ", vbExclamation + vbOKOnly, ConAppName
End If

Wayne
 
Thanks!

Wayne,

thanks for your quick response! It works exactly as I wanted.
gr
Alaric
 

Users who are viewing this thread

Back
Top Bottom