resetting fields thru code

S

SF

Hi,

I put a button on an unbound form to reset several unbound fields to null.

The code below give me an error "Method or data member not found"

Dim ctl As Control

For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
Me.ctl = ""
End If

Next ctl

SF
 
A

Allen Browne

In the loop you need:
ctl = Null

Me.ctl would expect a control literally named "ctl". Your ctl variable is
already a reference to the text box.

Also note that there is a very big difference between Null and a zero-length
string. see:
Nulls: Do I need them?
at:'
http://allenbrowne.com/casu-11.html

There are other conditions where your code could fail as well, e.g. a text
box bound to an expression such as:
=Date()
 

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