|
-
Nov 30th, 2014, 09:20 PM
#1
[RESOLVED] Object variable or With block variable not set (Error 91) Usercontrol
Hi,
I am moving some code of mine over to a user control but I am receiving "Object variable or With block variable not set (Error 91)" when I click the command button.
Code:
Public UserControl1 As UserControl1
Private Sub cmdRoll_Click()
UserControl1.Roll
End Sub
Private Sub Form_Load()
Set UserControl1 = UserControl1
End Sub
If I change the set line to
Code:
Set UserControl1 = New UserControl1
I receive "Invalid use of New keyword".
Why is this happening?
Thanks,
Nightwalker
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Nov 30th, 2014, 09:57 PM
#2
Re: Object variable or With block variable not set (Error 91) Usercontrol
Why would you try to set an object to a new instance of an object and use the same name as the original. Even if that would work it would be rather silly and a total waste of code and cpu time.
Have you added the usercontrol to your form?
If so does it not have the name UserControl11 ? That would be the default.
Also if it is added then you do not need to dim it and you do not need to set it and if you did you would have to use a different name from the original.
For example you can
Code:
Dim txtB as TextBox
Set txtB=Text1
You can not
Code:
Dim TextBox as textbox
Set TextBox=TextBox
Also if you want to add a control at run time then you have to use the add method of the controls collection
-
Dec 1st, 2014, 07:47 PM
#3
Re: Object variable or With block variable not set (Error 91) Usercontrol
 Originally Posted by DataMiser
If so does it not have the name UserControl11 ? That would be the default.
That was the problem! For some reason the default control had a name of "UserControl11" when I placed on the form even though double checking the name of the user control in the IDE it is "UserControl1". Removing the extra "1" solved the problem. Although, I still do not understand why it the default did not have the same name as the user control?
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Dec 1st, 2014, 07:54 PM
#4
Re: Object variable or With block variable not set (Error 91) Usercontrol
 Originally Posted by Nightwalker83
Although, I still do not understand why it the default did not have the same name as the user control?
Copy and paste 3 textboxes to a form and you get: Text1, Text2, Text3. So copy 3 Usercontrol1 and you get Usercontol11, Usercontol12, Usercontol13
-
Dec 1st, 2014, 08:15 PM
#5
Re: Object variable or With block variable not set (Error 91) Usercontrol
Yep the real problem is that you did not name your user control. By default it will be UserControl1 and when you add any control to a form it always takes its name and adds a number by default the first 1 being 1 so with a default user control you get UserControl11. This is normal behavior
-
Dec 2nd, 2014, 12:47 AM
#6
Re: Object variable or With block variable not set (Error 91) Usercontrol
 Originally Posted by LaVolpe
Copy and paste 3 textboxes to a form and you get: Text1, Text2, Text3. So copy 3 Usercontrol1 and you get Usercontol11, Usercontol12, Usercontol13
 Originally Posted by DataMiser
Yep the real problem is that you did not name your user control. By default it will be UserControl1 and when you add any control to a form it always takes its name and adds a number by default the first 1 being 1 so with a default user control you get UserControl11. This is normal behavior
Thanks!
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|