Clearing Fields - Inconvenient Control Sources



I have a Clear button that cycles through all controls in a form and fills
them with null values. The code for that is:

Dim ctl As Access.Control
For Each ctl In Me.Controls
If ((ctl.ControlType = acTextBox) Or (ctl.ControlType = acComboBox)
Or (ctl.ControlType = acCheckBox)) Then
ctl.Value = Null
End If
Next ctl

However, there are a few fields that have a control source linked to a combo
box, and when the code gets to these boxes I get an error: cannot assign a
value to this control. Understandable, since each field is supposed to be
equal to a column from the associated combo box.

I tried to add an exception to the If statement, but I can't figure out what
the property is for checking to see if a control has a control source.
(pseudocode: If ctl.controlsource = null then assign null value)

Thanks in advance!





Ahhhhh HA! lol, I didn't expect that to work since the dropdown box didn't
display that property!

Thanks Ofer!


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