CompleteForm - BeforeUpdate

G

Guest

Hello,

Below is the code I have in the Form Properties of a Form and on the Events
Tab in the BeforeUpdate area under that tab. This code works great except I
need to say if the control is enabled = false then go to next control.

How could I change the code for this extra addition.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim blnContinue As Boolean
Dim ctl As Control
blnContinue = True
For Each ctl In Me.Controls
If ctl.Tag = "Required" Then
If IsNull(ctl) Then
MsgBox "You must fill in the " & ctl.ControlSource & " field."
Cancel = True
ctl.SetFocus
Exit For
End If
End If
Next ctl
Set ctl = Nothing


Me.LastUpdate = Now()
End Sub

Thanks,
 
G

Guest

Yeah, I'm not suprised. I didn't think about it at the time, but you are not
filtering the controls you are looking at and some control types don't
support the enabled property. The correct way to do this would be to add a
line that only looks at the types of controls that have data.

If ctl.Type = acTextBox or ctl.Type = acComboBox.... etc.
 
G

Guest

Klatuu,

This worked:


Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim blnContinue As Boolean
Dim ctl As Control
blnContinue = True
For Each ctl In Me.Controls
If ctl.Tag = "Required" Then
If ctl.Enabled = True Then
If IsNull(ctl) Then
MsgBox "You must fill in the " & ctl.ControlSource & " field."
Cancel = True
ctl.SetFocus
Exit For
End If
End If
End If
Next ctl
Set ctl = Nothing


End Sub

I appreciate your input. It gave me the idea on how to get a fix for this
problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top