Thread: Edit userform
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Kilmer Bob Kilmer is offline
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/