error using SET object to a frame on a userform

BBCrawford

New Member
Joined
Jun 22, 2007
Messages
11
Excel 2016 ProPlus (but the problem occurs in Excel 2013 as well)
I have a userform with a number of Frames on it that that are layered on top of a "baseline" frame that has command buttons on it for selecting the Frames to be overlayed, exposing additional controls to the user. When I activate the myuserform I properly size the baseline frame and set all the other frames widths to 0 (their height is made=baseline). When the user selects the required action the appropriate frame is expanded overtop of part of the baseline frame exposing the additional controls.
Because I am switching frames back and forth (ie to appear/not appear by setting width to zero or to the overlap width) I need to keep track of the currently active frame so I know which one to set width =0 when the user selects the next frame. To handle this initially I have to set a "current frame" to the "baseline" frame
This "CurrentFrame" is set in the activate event of the form (in the forms code):
-in the userform's declaration:
Public CurrentFrame as msforms.Frame then in the activate event
SET CurrentFrame=myuserform.BaselineFrame

then after any new frame selection I set the (in the command button click event (actually in a common Sub))
CurrentFrame.width =0
SET CurrentFrame = myuserform.newFrame
CurrentFrame.width=400

This all works wonderfully ... until it doesn't..
I can test this 10-20+ times (or sometimes just once) and it will work with any combination of closing and opening the form and closing and opening the WB and opening and closing Excel.
At some point when opening (activating) the form it will fail on the;

SET CurrentFrame=myuserform.BaselineFrame with a "Type Mismatch" error​

In the debugger if, at the error, I display the BaseLineFrame.name it is no longer the name of the Frame but the name of a commandbutton on the BaseLineFrame (if I remove that Button from the BaseLineFrame it just changes to another button)

I have tried opening/closing the form with Show/Hide & Show/Unload but the same.
Periodically when I get this failure and I then close the WB I will get an "Out of Memory" error.
Also, there is another WB open at the same time (hidden) that this WB updates as part of its normal processing (neither WBs are particularly large)

Help desperately needed
Thanks
Brain
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,215,061
Messages
6,122,922
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top