PDA

View Full Version : [SOLVED] Code Execution Interrupted when Reloading Userform



magelan
09-26-2013, 08:53 AM
Is there something that breaks when you do a userform reload?

I've got a userform that I load up via pressing command button - does a userform.show

Inside userform.show i've got several buttons that display data from the worksheet and allow the user to delete, insert, etc, rows. So that my visible data is current, i execute the following code at the end of each command button's script


Call module1.reloadForm
...
sub reloadForm()
unload userform1
userform1.show
end sub


This seems to work great - except every now and then, whenever I use my buttons, i come up with "Code Execution Interrupted". Pressing the DEBUG button shoots me off to a completely random looking piece of code - it has rarely hit the same line twice.

What the heck causes this?

EDIT: I've actually commented out the lines of code that involve unloading and reloading the form and im STILL getting random code execution halts.

snb
09-27-2013, 02:30 AM
Why would you load reload so many times ?

I'd prefer to hide / show.

But to be honest: when I use a userform it will be loaded once (when th task begins) and unloaded once (when the whole task is ready); and that period can very well be a whole working day, in which the user doesn't even notice he/she is working in Excel/Word/Outlook.

Kenneth Hobs
09-27-2013, 05:55 AM
Why not show the Userform modeless so that they can interact with the data in the workbook while the userform is shown?

SamT
09-27-2013, 07:09 AM
Ken's suggestion +


Const DefaultHeight = Me. Height
Const Default Width = Me.Width

Private Sub MinimizeButton_Click()
With Me
.Controls.Visible = False
.RestoreButton.Visible = True
.Width = RetoreButton.Widht + 2
.Height = RestoreButton.Height + 'As needed to show properly
End Sub

Private Sub RestoreButton_Click()
With Me
.Controls.Visible =True
.RestoreButton.Visible = False
.Width = DefaultWidth
.Height = DefaultHeight
End Sub

'Has Errors, omissions, and mistakes

Place RestoreButton at top Left of Form

magelan
09-30-2013, 07:31 AM
It seems like all I needed to do was reboot - it hasnt given me a single Code Execution Interrupted since then.

The user shouldnt be able to interact with the data at all because they constantly introduce anomalies into the data that the program is expecting. I've seen users go into CSV's and turn half the data into tab-delimited and wonder why it doesnt import right.

I do need to refresh my UF though, after a row has been inserted or removed i need to update the listbox on my userform & reset all the fields.. i built a Refresh sub.

SamT
09-30-2013, 02:43 PM
Worksheet.Protect UserInterfaceOnly:=True
Workbook.Protect Structure:=True