Button To clear text boxs!

B

Bob

How do I go about assigning a button to clear the 4 other text boxes on that
form?

Thanks in advance.........Bob Vance
 
N

Nikos Yannacopoulos

Bob,

The code behind the button should be:

For each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
Me.Controls(ctl.Name) = Null
End If
Next

HTH,
Nikos
 
N

Nikos Yannacopoulos

Not necessary if not Option Explicit... I'm too lazy to Dim all my
variables. I know I should, but then again, let whoever does nothing
they know they shouldn't, cast the first stone :)
 
N

Nikos Yannacopoulos

Bob,

Open the form in design view, select the button, desplay the properties
window and select tab Events; place the cursor in the On Click property
cox and click on the little button with the ellipsis symbol that appears
on the right. You will be taken to a VA editor screen, with either two
lines od code like:

Private Sub Command1_Click()

End Sub

where Command1 would actually be the name of your command button, or the
same with some lines of code in between, if you carried through the
command button wizard instead od cancelling out, when you created the
command button. In the latter case, delete all lines of code in between
the two shown above. Then paste the code I gave you in between those two
lines, return to form design, save and you're done.

HTH,
Nikos
 
K

Keith

Bob said:
Sorry can you tell me how to put a code behind a button, I am a Newbie,
Thanks Bob
Open your form in design view and double-click your command button. This
should reveal the 'properties' box (if it wasn't already there). Click the
'events' tab and select 'Event Procedure' from the drop-down list for the
'on click' event (click at the right-hand side of the seemingly empty box, a
drop-down arrow will appear).

Once you have selected 'Event Procedure' from the drop-down there should be
a small box with three dots in it - click this and paste the code between
"private sub ..." and "end sub" for your command button name.

To make sure there are no errors in the code you must compile it. Do this
by selecting "compile" from the "debug" menu. If all is well, close the
code window and save your form.

HTH - Keith.
www.keithwilby.com
 
B

Bob

I did that and now I am getting a yellow line on this part of the code
Me.Controls(ctl.Name) = Null
Thanks Bob
 
K

Keith

Bob said:
I did that and now I am getting a yellow line on this part of the code
Me.Controls(ctl.Name) = Null
Thanks Bob
If you have "Option Explicit" at the very top of the code then you need this
as the first line for your button:

Dim ctl as Control

Regards,
Keith.
www.keithwilby.com
 
N

Nikos Yannacopoulos

Bob,

Keith's suggestion will fix a possible problem, but this is not the only
possible problem. If it's not fixed pls post back the error message.

Nikos
 
B

Bob

Still getting a yellow line through Me.Controls...

Private Sub Command40_Click()
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
Me.Controls(ctl.Name) = Null
End If
Next

End Sub
Thanks Bob
 
K

Keith

Bob said:
Still getting a yellow line through Me.Controls...

Private Sub Command40_Click()
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
Me.Controls(ctl.Name) = Null
End If
Next

End Sub

Works fine for me. Do you have a library reference to DAO 3.6 set? Check
under References from the Tools menu in a code window.
 

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