Full Version: Cotrols on a form (with tag=req)
UtterAccess Forums > Microsoft® Access > Access Forms
doran_doran
I have about 12 text boxes that cannot be blanked when user click on the save button. why this code going through all the controls when i told it to look for actextbox and tag=req.
Any input will be very appreciated.... Thanks
Dim ctl As Control

For Each ctl In Me.Section(0).Controls 'detail section

Select Case ctl.ControlType
Case acTextBox
If ctl.Tag = "req" Then
If IsNull(ctl) Then
MsgBox (ctl.NAME & " Certain fields must be populated."), vbCritical, "Missing Data"
'Exit Sub
End If
End If
'Case Else
' MsgBox "case else is showin"
End Select

Next ctl
RedLineSkis
I am not sure if I understand the question but if you want to know why the code is "going through all the controls" I believe that would be because of your FOR loop. i.e. "For Each ctl In Me.Section(0).Controls 'detail section" Your code is looping through each control in your detail section. OR are you talking about all the controls are looping through this code eventhough the ControlType is not set as an acTextBos and the Tag does not = "req". You could always try using Str()
doran_doran
It was going through all the controls instead of just actextbox and tag="watever". well. I redid my code and following code seems to be working...
Function check4null()
Dim ctl As Control
For Each ctl In Me.Controls
With ctl
Select Case .ControlType
Case acTextBox
If ctl.Tag = "req" And IsNull(ctl) Then
MsgBox ctl.NAME & " must be populated."
ctl.SetFocus
ctl.BackColor = vbYellow
End If
End Select
End With

Next ctl
End Function
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.