Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / New Users / July 2005

Tip: Looking for answers? Try searching our database.

Button To clear text boxs!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bob - 30 Jun 2005 05:03 GMT
How do I go about assigning a button to clear the 4 other text boxes on that
form?

Thanks in advance.........Bob Vance
Nikos Yannacopoulos - 30 Jun 2005 10:23 GMT
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

> How do I go about assigning a button to clear the 4 other text boxes on that
> form?
>
> Thanks in advance.........Bob Vance
Keith - 30 Jun 2005 10:59 GMT
> Bob,
>
[quoted text clipped - 5 lines]
>     End If
> Next

Not forgetting "Dim ctl as Control" ;-)

Keith.
www.keithwilby.com
Nikos Yannacopoulos - 30 Jun 2005 12:41 GMT
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 :-)
Keith - 30 Jun 2005 13:52 GMT
> Not necessary if not Option Explicit.

Ah, duly noted :o)
Bob - 30 Jun 2005 23:39 GMT
Sorry can you tell me how to put a code behind a button, I am a Newbie,
Thanks Bob

>> Not necessary if not Option Explicit.
>
> Ah, duly noted :o)
Nikos Yannacopoulos - 01 Jul 2005 08:24 GMT
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

> Sorry can you tell me how to put a code behind a button, I am a Newbie,
> Thanks Bob
>
>>>Not necessary if not Option Explicit.
>>
>>Ah, duly noted :o)
Bob - 01 Jul 2005 08:41 GMT
I did that and now I am getting a yellow line on this part of the code
Me.Controls(ctl.Name) = Null
Thanks Bob

> Bob,
>
[quoted text clipped - 24 lines]
>>>
>>>Ah, duly noted :o)
Keith - 01 Jul 2005 09:58 GMT
>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
Nikos Yannacopoulos - 01 Jul 2005 11:17 GMT
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
Keith - 01 Jul 2005 08:36 GMT
> 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
Bob - 01 Jul 2005 19:14 GMT
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
>> Sorry can you tell me how to put a code behind a button, I am a Newbie,
>> Thanks Bob
[quoted text clipped - 15 lines]
> HTH - Keith.
> www.keithwilby.com
Bob - 01 Jul 2005 21:45 GMT
This was at the very top of the page:
Option Compare Database
Thanks bob

> Still getting a yellow line through Me.Controls...
>
[quoted text clipped - 28 lines]
>> HTH - Keith.
>> www.keithwilby.com
Nikos Yannacopoulos - 04 Jul 2005 08:05 GMT
No apparent reason. What is the exact error message?

Nikos
Keith - 04 Jul 2005 08:26 GMT
> Still getting a yellow line through Me.Controls...
>
[quoted text clipped - 7 lines]
>
> 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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.