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

Alright I have a program that when opened pulls up a userform. There i
a button on this form that allows you to edit the form. When thi
button is clicked the first form is unloaded and a new form comes up
This second form takes the data that you want and uses it to change th
data on the first form (well that's what I want it to do). I am usin
the following code to do this (change caption).

Dim VBC as object

Set VBC
Workbooks("3PUserFormTest.xls").VBProject.VBCompon ents("UserForm1")
VBC.Designer.Controls("ckwater").Caption = txNew

Problem: If I run it from the program window of the second form i
works fine, but if I close the program and reopen it so that the firs
form loads when I get to the second form and press okay so that it wil
run the above code it gives me an error. The error is as follows.

Run-time error '91':
Object Variable or With block variable not set

It highlights the last line of the above code, but I can't seem to fin
an error. I even placed the code into a different window and ran it b
itself. It worked fine. This has been stumping me all day. Pleas
help!

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 280
Default Edit userform

In "Object Variable or With block variable not set" the emphasis should be
on SET. Your Set statement has failed to find UserForm1, and VBC's value is
almost assuredly Nothing when the next line excutes. Set a break point on
the VBC.Designer.... line and run your code. When it stops, open the Locals
window (View Locals) and check the value of VBC. If it is Nothing, that
will confirm the diagnosis.

So, don't unload the first form. It's the first (instance of the first) form
you want ot change, isn't it? Just Hide it. Use UserForm1.Hide.

Forms can be Loaded, Shown, Hidden, Shown, Hidden, (ad infinitum) and
Unloaded. Once Unloaded, the form is gone. Kaput. If one comes up, it is a
new one (an new "instance"). (BTW, if you Show a form, Show Loads it first.)

Load UserForm1
UserForm1.Show
UserForm1.Hide
Unload UserForm1

"lostthought " wrote in message
...
Alright I have a program that when opened pulls up a userform. There is
a button on this form that allows you to edit the form. When this
button is clicked the first form is unloaded and a new form comes up.
This second form takes the data that you want and uses it to change the
data on the first form (well that's what I want it to do). I am using
the following code to do this (change caption).

Dim VBC as object

Set VBC =
Workbooks("3PUserFormTest.xls").VBProject.VBCompon ents("UserForm1")
VBC.Designer.Controls("ckwater").Caption = txNew

Problem: If I run it from the program window of the second form it
works fine, but if I close the program and reopen it so that the first
form loads when I get to the second form and press okay so that it will
run the above code it gives me an error. The error is as follows.

Run-time error '91':
Object Variable or With block variable not set

It highlights the last line of the above code, but I can't seem to find
an error. I even placed the code into a different window and ran it by
itself. It worked fine. This has been stumping me all day. Please
help!!


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Edit userform

that didn't work. I was already hiding UserForm1. The only time I unloa
them is when cancel is pressed. I changed those to hide as well to se
if it would help but nothing. I looked inside the locals window and VB
was blank to the right of it. There is a plus sing to the left and whe
clicked it brings up a list of stuff. The only thing that says nothin
is Designe

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 280
Default Edit userform

Then Designer is not initialized. You'll have to find out why not. BTW, what
is Designer? it is not ringing any bells for me.

"lostthought " wrote in message
...
that didn't work. I was already hiding UserForm1. The only time I unload
them is when cancel is pressed. I changed those to hide as well to see
if it would help but nothing. I looked inside the locals window and VBC
was blank to the right of it. There is a plus sing to the left and when
clicked it brings up a list of stuff. The only thing that says nothing
is Designer


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Edit userform

Designer is the programmatic equivalent of editing the userform manually in
the VBE.

--
Regards,
Tom Ogilvy

"Bob Kilmer" wrote in message
...
Then Designer is not initialized. You'll have to find out why not. BTW,

what
is Designer? it is not ringing any bells for me.

"lostthought " wrote in

message
...
that didn't work. I was already hiding UserForm1. The only time I unload
them is when cancel is pressed. I changed those to hide as well to see
if it would help but nothing. I looked inside the locals window and VBC
was blank to the right of it. There is a plus sing to the left and when
clicked it brings up a list of stuff. The only thing that says nothing
is Designer


---
Message posted from http://www.ExcelForum.com/







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Edit userform

yeah Designer allows you to Change the UserForm using code. Anybody hav
any idea why this isn't initializing

--
Message posted from http://www.ExcelForum.com

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 280
Default Edit userform

You said:
"Problem: If I run it from the program window of the second form it
works fine,..."

[Because form1 is in "design mode" (not loaded); it is not in run mode.]

"but if I close the program and reopen it so that the first
form loads when I get to the second form and press okay so that it will
run the above code it gives me an error."

[Because then the form is in run mode, not design mode. You cannot "design'
a form that is running.]

I can reproduce the error thus:

Sub main() 'in standard module
UserForm2.Show vbModeless
Load UserForm1
End Sub

Private Sub UserForm_Click() 'in UserForm2
Dim VBC As Object

Set VBC = Workbooks("Book1.xls").VBProject.VBComponents("Use rForm1")
If VBC.Designer.Controls("ckwater").Caption = "hi" Then
VBC.Designer.Controls("ckwater").Caption = "lo"
Else
VBC.Designer.Controls("ckwater").Caption = "hi"
End If
End Sub

Regards,
Bob Kilmer


"lostthought " wrote in message
...
yeah Designer allows you to Change the UserForm using code. Anybody have
any idea why this isn't initializing?


---
Message posted from http://www.ExcelForum.com/



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 280
Default Edit userform

Think of a form in design mode (when it is not loaded or running) as a
class. You can modify a class at design time but not at run time. When you
are using the designer, you are modifying the *class* programatically like
you would interactively in the IDE.

Once you load "the form," you have created an instance of the class in
memory. You can set a caption using the *run time* properties of the
instance of the class, but the class itself cannot be modified, any more
than you can write code while the code is executing.

If you want to use the designer on form 1, unload all instances of form 1,
"design" it (i.e., modify the class), then load and/or show a new instance
of the modified class.

I hope this finally clears things up.

Bob Kilmer

"lostthought " wrote in message
...
yeah Designer allows you to Change the UserForm using code. Anybody have
any idea why this isn't initializing?


---
Message posted from http://www.ExcelForum.com/



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Edit userform

Thanks again. Appreciate all the help


---
Message posted from http://www.ExcelForum.com/

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
Edit exsisting data with userform Geo Excel Discussion (Misc queries) 2 October 1st 07 07:38 PM
Multiple Userform Hold Data to edit bg18461[_8_] Excel Programming 2 June 4th 04 03:10 AM
Edit a userform Debra Dalgleish Excel Programming 0 February 7th 04 01:57 PM
View Row Data in UserForm / Edit Pete T[_2_] Excel Programming 1 October 17th 03 10:36 PM
Code to edit directly in cells from userform Tom Ogilvy Excel Programming 0 September 7th 03 10:27 PM


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