"ryguy7272" <(E-Mail Removed)> wrote in message
news:683FD014-2497-4DA0-A166-(E-Mail Removed)...
>I have been using the code below in an Excel UserForm for a while without
>any
> problems.
>
> Private Sub Command337_Click()
>
> Dim C As MSForms.Control
> For Each C In Me.Controls
> If TypeOf C Is MSForms.TextBox Then
> C.Text = ""
> End If
> Next C
>
> End Sub
>
> I copied/pasted it into an Access Form so I could clear the values of all
> Controls, but I get a message that says Compile Error: User-defined type
> not
> defined. Are the Controls in Access different from the controls in Excel?
> I
> read several posts on this DG; still not able to clear all the Controls in
> my
> Access Form.
>
> I have several textboxes and several ComboBoxes. How can I clear all
> values
> in all Controls in my Access Form? Set to Null?
Yes, the Access Control object is completely different from the MSForms
controls used in Excel and Word. Also, an Access control's Text property is
only available under special circumstances, and is only used for very
special purposes. It's the Value property -- which is the default property
of most Access controls, and hence need not be named explicitly -- that you
would normally work with. Further, you mostly want to set controls to Null
to clear them, not to "", because "" is not a valid value for many controls.
With all that in mind, we can revise your code as follows:
'----- start of revised code -----
Private Sub Command337_Click()
Dim C As Access.Control ' or just "As Control"
For Each C In Me.Controls
If TypeOf C Is Access.TextBox Then
C = Null
End If
Next C
End Sub
'----- end of revised code -----
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)