#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Form help

I have the following code:

UserForm1.Show
Load UserForm2

UserForm1 has ListBox1 of open workbooks and RefEdit1 control as well as
CommandButton1 and CommandButton2. Clicking CommandButton1 runs code that
copies the range selected in RefEdit1 to a specified area - no problems
here. CommandButton2 is supposed to be a Cancel button and is where the
problem is. When the Cancel button on UserForm1 is clicked, I want to
unload UserForm1 and continue to the next line of code, which is to Load
UserForm2. At this point, I get the Application-defined or object-defined
error (runtime error 1004). If, on UserForm1, I select a range and click
the OK button, everything works fine, the code bombs out if I Cancel. Any
thoughts?

Also, I may change the code to completely dump out of the macro upon
clicking CommandButton2 on UserForm1. How would I do this?

TIA

--
Michael J. Malinsky
Pittsburgh, PA

"I am a bear of very little brain, and long
words bother me." -- AA Milne, Winnie the Pooh


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Form help

Hi Michael

If you run this

Sub test()
UserForm1.Show
MsgBox "Yo da man"
End Sub

then you'll see that the message doesn't appear until Userform1 is long
gone, the macro has no idea what happened with the form. So you need some
way to transfer the actions/the result from Userform1 back to the macro that
stays im memory even when the form goes. One way is to set a public variable
to something spesific. Another is to write something temporarily to cells,
to a textfile, into the registry, .... A third way might be to wrap the
userform1 display/action thing into a separate function. And there are
probaly tons of other approaches.

HTH. best wishes Harald

"Michael Malinsky" skrev i melding
...
I have the following code:

UserForm1.Show
Load UserForm2

UserForm1 has ListBox1 of open workbooks and RefEdit1 control as well as
CommandButton1 and CommandButton2. Clicking CommandButton1 runs code that
copies the range selected in RefEdit1 to a specified area - no problems
here. CommandButton2 is supposed to be a Cancel button and is where the
problem is. When the Cancel button on UserForm1 is clicked, I want to
unload UserForm1 and continue to the next line of code, which is to Load
UserForm2. At this point, I get the Application-defined or object-defined
error (runtime error 1004). If, on UserForm1, I select a range and click
the OK button, everything works fine, the code bombs out if I Cancel. Any
thoughts?

Also, I may change the code to completely dump out of the macro upon
clicking CommandButton2 on UserForm1. How would I do this?

TIA

--
Michael J. Malinsky
Pittsburgh, PA

"I am a bear of very little brain, and long
words bother me." -- AA Milne, Winnie the Pooh




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Form help

Michael,

What is the code for CommandButton2?

The following works for me loading (and showing) UserForm2 after UserForm1 has
been unloaded,

In a Code Module:
'*****
Sub test764()
UserForm1.Show
Load UserForm2
UserForm2.Show
End Sub
'*****

In the code for UserForm1:
'*****
Private Sub CommandButton2_Click()
Unload UserForm1
End Sub
'*****

Regards
Anders Silven

"Michael Malinsky" skrev i meddelandet
...
I have the following code:

UserForm1.Show
Load UserForm2

UserForm1 has ListBox1 of open workbooks and RefEdit1 control as well as
CommandButton1 and CommandButton2. Clicking CommandButton1 runs code that
copies the range selected in RefEdit1 to a specified area - no problems
here. CommandButton2 is supposed to be a Cancel button and is where the
problem is. When the Cancel button on UserForm1 is clicked, I want to
unload UserForm1 and continue to the next line of code, which is to Load
UserForm2. At this point, I get the Application-defined or object-defined
error (runtime error 1004). If, on UserForm1, I select a range and click
the OK button, everything works fine, the code bombs out if I Cancel. Any
thoughts?

Also, I may change the code to completely dump out of the macro upon
clicking CommandButton2 on UserForm1. How would I do this?

TIA

--
Michael J. Malinsky
Pittsburgh, PA

"I am a bear of very little brain, and long
words bother me." -- AA Milne, Winnie the Pooh



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
Formula (off form) that completes form data based on a result lldiel Excel Worksheet Functions 2 November 24th 09 11:09 PM
excel form. Need data extracted to spreadsheet each time a form co MikeR-Oz Excel Discussion (Misc queries) 4 April 5th 09 05:18 AM
Using a template form, advance a form number everytime you open ShoDan Excel Discussion (Misc queries) 1 January 31st 08 01:34 PM
Can a form made in Excel 2002 be converted into a fillable form? Paraclete Excel Discussion (Misc queries) 1 February 20th 07 09:20 PM
how can I make a form number change everytime the form is opened babydumplingspita Excel Worksheet Functions 1 October 10th 05 07:58 PM


All times are GMT +1. The time now is 08:57 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"