Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default User Form Button Code

I set up a userform with a button that on click runs a piece of code
to reset all the fields on the form.

It reads something like this:
-------------------
Private Sub Clearform_Click()

With userform1

..Name = ""
..Address1 = ""
..Address2 = ""
..Address3 = ""
..Address4 = ""
..postcode = ""

End With

End Sub
---------------------


The button worked fine when it was first set up and then all of a
sudden decided it had had enough. Now when the button is clicked it
runs the lines of the macro in order requiring the button to be
clicked again between each one.

I have tried completely replacing the button and code, and have run
the workbook on a different system so the error must be in the
programming and not the computer set up.

What have I done? - Help please!

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default User Form Button Code

Have you coded other events associated with the change event for the
controls that you are clearing - perhaps with error suppression. When you
clear the controls, this could be triggering their change event and an error
could cause the code to halt. I don't see anything wrong with the code you
show. You might put in a global variable at the top of the userform routine
and then have all the event code check the value of that variable before
doing anything. If the variable is set to true, you would add code to
immediately exit the event, and if false to proceed - if that routine needs
to block other events, it would set the variable to true , process, then set
it to false just before exiting. For example

Public bBlockEvents as Boolean

Private Sub Clearform_Click()

if bBlockEvents then exit sub
bBlockEvents = True
With userform1

.Name = ""
.Address1 = ""
.Address2 = ""
.Address3 = ""
.Address4 = ""
.postcode = ""
End With
bBlockEvents = False
End Sub

Private Sub Name_Change()
if bBlockEvents then Exit sub
' process change in textbox Name
' no need to block events

End Sub

as an example

--
Regards,
Tom Ogilvy



"Debs" wrote in message
om...
I set up a userform with a button that on click runs a piece of code
to reset all the fields on the form.

It reads something like this:
-------------------
Private Sub Clearform_Click()

With userform1

.Name = ""
.Address1 = ""
.Address2 = ""
.Address3 = ""
.Address4 = ""
.postcode = ""

End With

End Sub
---------------------


The button worked fine when it was first set up and then all of a
sudden decided it had had enough. Now when the button is clicked it
runs the lines of the macro in order requiring the button to be
clicked again between each one.

I have tried completely replacing the button and code, and have run
the workbook on a different system so the error must be in the
programming and not the computer set up.

What have I done? - Help please!

Thanks



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
User form and Command button Marilyn Excel Discussion (Misc queries) 3 May 9th 07 12:50 AM
Command Button on User form for Printing Anthony Slater Excel Discussion (Misc queries) 2 September 7th 05 02:01 PM
use a button to open a user form? Hru48 Excel Discussion (Misc queries) 1 September 1st 05 07:41 PM
User Form Code mully New Users to Excel 9 May 22nd 05 07:54 PM
A "previous" button on a user form Anthony Slater Excel Discussion (Misc queries) 3 November 29th 04 05:57 PM


All times are GMT +1. The time now is 04:33 PM.

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"