By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,097 Members | 1,917 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,097 IT Pros & Developers. It's quick & easy.

conditionally enabling a form control

P: n/a
Perhaps someone in this group smarter than me can help me with this
problem. On a data entry form, I have placed a command button to
"close" the form when the user is finished entering the required data.
To make sure the user enters complete data in every text control, I
have set the button's "enabled" state to false when the form loads. I
have placed the following code in the form's general code section.
Other than the command button, the controls on the form consist of two
text boxes and one combobox in that order. I call the following
subroutine from each of the control's "OnChange" Events, but it does
not change the command button's state to "enabled." I've tried calling
the procedure from other control events like AfterUpdate, Dirty, etc.,
but no luck.

Thanks
Scott

Dim frmName As String
Dim ctl As Control
Dim X As Boolean

frmName = Me.Name

For Each ctl In [Forms]!frmName
If IsEmpty(ctl) Or IsNull(ctl) Then
X = False
End If
Next ctl

cmdDone.Enabled = X

Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Scott wrote:
Perhaps someone in this group smarter than me can help me with this
problem. On a data entry form, I have placed a command button to
"close" the form when the user is finished entering the required data.
To make sure the user enters complete data in every text control, I
have set the button's "enabled" state to false when the form loads. I
have placed the following code in the form's general code section.
Other than the command button, the controls on the form consist of two
text boxes and one combobox in that order. I call the following
subroutine from each of the control's "OnChange" Events, but it does
not change the command button's state to "enabled." I've tried calling
the procedure from other control events like AfterUpdate, Dirty, etc.,
but no luck.

Thanks
Scott

Dim frmName As String
Dim ctl As Control
Dim X As Boolean

frmName = Me.Name

For Each ctl In [Forms]!frmName
If IsEmpty(ctl) Or IsNull(ctl) Then
X = False
End If
Next ctl

cmdDone.Enabled = X


You dimmed X as boolean with a default value of false. So you cycled
through the text fields and no matter if they are all filled in or not
you will always have a false value.

Set x to True before you start scanning the controls.

I'm not sure you need to check using IsEmpty(). However, a numeric
value may default to zero. Do you allow zeros?

BTW, you might want to check if the CTL is acTextBox so you aren't
scanning isn't a label or command button or list box. See ControlType
in help.

Nov 13 '05 #2

P: n/a
Thank you very much. I missed that small but critical piece of logic.
Scott

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.