I've created a custom inputbox so user can select which data to export (to an Excel ws in this case).

On my form, that will call the custom inputbox, I have a Listview control that shows a popup menu when I right-click on the listview and one of the menu items there is Export 2 Excel.

Also on the form there is a button that also shows a popup menu when I click the button and one of the menu items there is also Export 2 Excel.

Both popup menus call the same function named Xport2Xl. There is no parameters for the function. In this function I call the custom inputbox for user to select his data (in the form of a string).

If I click the button the popup menu shows and I click the Export 2 Excel menu item. The custom inputbox shows, I enter my parameters and click OK. The program then crash with error message Run-time error '5': Invalid procedure call or argument. The crash happens on the line
Code:
Me.Hide
in the custom inputbox. I tried putting On Error Resume Next before the Me.Hide line but the error still occurs.

I added a MsgBox right after the Me.Hide line to show what the entered parameters are (just for trying to trace the problem) and when I click OK on the error message the added MsgBox displays the parameters entered. Clicking OK on that MsgBox the exits the program completely.

However...

If I right-click on the listview and select Export 2 Excel there, the custom inputbox is displayed, I enter my parameters and click OK. The program works 100%. No crash.

If I retry the click on the button, after I did the right-click on the listview, select the menu item Export 2 Excel the custom inputbox displays, I enter the exact same parameters and click OK. The program works 100%

All the other menu items works without any problem in both popup menus.

An added complication...

When running the program from the VB Editor both popup menus calls work. The error only occurs in the compiled program.

Does anybody have any suggestions why this could happen or what I can try to fix the problem. I can remove the menu item from the button popup menu but I would like to keep it there if possible.