Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Clearing Form Values the easy Way???

Herro!! Okay, I have been clearing forms upon exiting them by
individual fields, and it is a pain in my ass. Example:

Sub ClearRWts()
RWts.Hide
RWts.textbox1.Clear
RWts.Caption.Clear
RWts.Pain.Clear
RWts.InMy.Clear
RWts.colon.Clear
RWts.textbox2.Clear
End Sub

So...let us say that the above code includes like 18 lines to clear an
entire form so that the next time it will be fresh and clean like a new
tissue from the kleenex box...Please tell me there is an easy way to do
this. I have tried the following, but they did not work:

RWts.Clear

RWts.Close

RWts.JustDeleteEverythingDammit

RWts.Values.Clear


Apparently, these are not allowed as they either only exist in my head,
or are not correct statements or syntax.

Oh dear stranger reading this, will you not help this poor soul who
must endure countless hours of useless line-by-line code entry?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default Clearing Form Values the easy Way???

Does this work for you: Placed in the userform code:

Private Sub OK_Button_Click()
Dim tBox As TextBox
For Each tBox In TextBoxes
tBox.Text = ""
Next
End Sub

" wrote:

Herro!! Okay, I have been clearing forms upon exiting them by
individual fields, and it is a pain in my ass. Example:

Sub ClearRWts()
RWts.Hide
RWts.textbox1.Clear
RWts.Caption.Clear
RWts.Pain.Clear
RWts.InMy.Clear
RWts.colon.Clear
RWts.textbox2.Clear
End Sub

So...let us say that the above code includes like 18 lines to clear an
entire form so that the next time it will be fresh and clean like a new
tissue from the kleenex box...Please tell me there is an easy way to do
this. I have tried the following, but they did not work:

RWts.Clear

RWts.Close

RWts.JustDeleteEverythingDammit

RWts.Values.Clear


Apparently, these are not allowed as they either only exist in my head,
or are not correct statements or syntax.

Oh dear stranger reading this, will you not help this poor soul who
must endure countless hours of useless line-by-line code entry?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Clearing Form Values the easy Way???

If you unload the form when you exit, it will be reinitialized when you show
it next (without clearing any controls).

--
Regards,
Tom Ogilvy

wrote in message
oups.com...
Herro!! Okay, I have been clearing forms upon exiting them by
individual fields, and it is a pain in my ass. Example:

Sub ClearRWts()
RWts.Hide
RWts.textbox1.Clear
RWts.Caption.Clear
RWts.Pain.Clear
RWts.InMy.Clear
RWts.colon.Clear
RWts.textbox2.Clear
End Sub

So...let us say that the above code includes like 18 lines to clear an
entire form so that the next time it will be fresh and clean like a new
tissue from the kleenex box...Please tell me there is an easy way to do
this. I have tried the following, but they did not work:

RWts.Clear

RWts.Close

RWts.JustDeleteEverythingDammit

RWts.Values.Clear


Apparently, these are not allowed as they either only exist in my head,
or are not correct statements or syntax.

Oh dear stranger reading this, will you not help this poor soul who
must endure countless hours of useless line-by-line code entry?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Clearing Form Values the easy Way???



" wrote:

Herro!! Okay, I have been clearing forms upon exiting them by
individual fields, and it is a pain in my ass. Example:

Sub ClearRWts()
RWts.Hide
RWts.textbox1.Clear
RWts.Caption.Clear
RWts.Pain.Clear
RWts.InMy.Clear
RWts.colon.Clear
RWts.textbox2.Clear
End Sub

So...let us say that the above code includes like 18 lines to clear an
entire form so that the next time it will be fresh and clean like a new
tissue from the kleenex box...Please tell me there is an easy way to do
this. I have tried the following, but they did not work:

RWts.Clear

RWts.Close

RWts.JustDeleteEverythingDammit

RWts.Values.Clear


Apparently, these are not allowed as they either only exist in my head,
or are not correct statements or syntax.

Oh dear stranger reading this, will you not help this poor soul who
must endure countless hours of useless line-by-line code entry?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Clearing Form Values the easy Way???



" wrote:

Herro!! Okay, I have been clearing forms upon exiting them by
individual fields, and it is a pain in my ass. Example:

Sub ClearRWts()
RWts.Hide
RWts.textbox1.Clear
RWts.Caption.Clear
RWts.Pain.Clear
RWts.InMy.Clear
RWts.colon.Clear
RWts.textbox2.Clear
End Sub

So...let us say that the above code includes like 18 lines to clear an
entire form so that the next time it will be fresh and clean like a new
tissue from the kleenex box...Please tell me there is an easy way to do
this. I have tried the following, but they did not work:

RWts.Clear

RWts.Close

RWts.JustDeleteEverythingDammit

RWts.Values.Clear


Apparently, these are not allowed as they either only exist in my head,
or are not correct statements or syntax.

Oh dear stranger reading this, will you not help this poor soul who
must endure countless hours of useless line-by-line code entry?




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Clearing Form Values the easy Way???

When you're attacking problems like this (when you don't know how
many controls there are) a good approach is to look for a solution that is
flexible and re-usable.

Here's one approach that I came up with using the tag property of the form
controls.

For each control that you want to refresh enter a value of Y (for Yes) as
the tag
property. You would then loop through each control, see if the tag has a Y
and
clear it. You might want to go one step further though. Sometime when you
clear
the fields on a form, you want some fields to have a default value like
today's
date in a date field or a zero in a number field.

To do this, in the tag property of each control you want to reset enter a Y
and
a new default value if you want one. For example: Y|0 (I've used | as a
separator).

Now your code simply has to loop through each control, see if the first
character
is Y and apply the default value if one exists otherwise use an empty string.

Here's some example code. Note that I've also included a parameter of the
form you wish to clear which means you can use the same code for many forms.
The function also has a return value which will tell you how many fields were
cleared.

Function ClearForm(ByRef frm As UserForm) As Long

Dim ctl As Control

' variant to store the default value which could be a
' string, number or date value.
Dim varDefault As Variant

' Loop through the collection of controls of the
' passed form parameter
For Each ctl In frm.Controls

' Determine if we want this control cleared
If UCase$(Left$(ctl.Tag, 1)) = "Y" Then

' retrieve default value (if any). This will be anything
' after the first two characters of the tag property
varDefault = Right(ctl.Tag, Len(ctl.Tag) - 2)

' Assess the default value
Select Case varDefault

' if the tag property has the word today, enter the date
Case "TODAY"
ctl.Value = Date

' Have as many special alternatives as you need
'case whatever

' Otherwise settle for the default value in the tag property.
' If the default was blank, this will enter an empty string
Case Else
ctl.Value = varDefault

End Select

' increment counter so we know how many fields were cleared
ClearForm = ClearForm + 1

End If

Next ctl

End Function


Good luck.

OfficeHacker

" wrote:

Herro!! Okay, I have been clearing forms upon exiting them by
individual fields, and it is a pain in my ass. Example:

Sub ClearRWts()
RWts.Hide
RWts.textbox1.Clear
RWts.Caption.Clear
RWts.Pain.Clear
RWts.InMy.Clear
RWts.colon.Clear
RWts.textbox2.Clear
End Sub

So...let us say that the above code includes like 18 lines to clear an
entire form so that the next time it will be fresh and clean like a new
tissue from the kleenex box...Please tell me there is an easy way to do
this. I have tried the following, but they did not work:

RWts.Clear

RWts.Close

RWts.JustDeleteEverythingDammit

RWts.Values.Clear


Apparently, these are not allowed as they either only exist in my head,
or are not correct statements or syntax.

Oh dear stranger reading this, will you not help this poor soul who
must endure countless hours of useless line-by-line code entry?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clearing the Values in a Drop - Down List Sagu Excel Discussion (Misc queries) 4 March 31st 06 03:32 AM
Clearing Form PEno1 Excel Programming 2 December 12th 04 09:18 PM
Custom form on opening - I think it's an easy one for the experts David Excel Programming 4 June 4th 04 06:32 AM
vba clearing out values stored in array chick-racer[_44_] Excel Programming 2 December 1st 03 09:05 PM
Clearing list from all form commandboxes josh ashcraft Excel Programming 2 August 19th 03 12:58 PM


All times are GMT +1. The time now is 01:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"