VBA Runtime error 400.

delaneyjm

Well-known Member
Joined
Apr 22, 2009
Messages
624
Hello Everyone,

Wondering if I can get a quick resolution to this one. I'm currently running a few VBA macros and userforms that are running pretty flawlessly except for one part. I'm receiving a run-time error (specifically, error code 400: form already displayed. can't show modally) when one someone clicks a Yes button on one form.

Here is the code for each of the userforms.

Code:
Option Explicit
Private Sub btnSubmit_Click()
    Dim strFile As String
    strFile = txtBatchID.Text
    Call BenefactorReceipts(strFile)
    Unload frmBenReceipts
End Sub
That form calls all the macros and they run fine without issue. Problem occurs when the macros finish executing and another userform asks if they want to run the macros again with a different file. If they click a No button, no issue. Click Yes, and it causes the run-time error. Code for that userform is below

Code:
Option Explicit
Private Sub btnNo_Click()
    Unload frmCompRecs
End Sub

Private Sub btnYes_Click()
    frmBenReceipts.Show
End Sub
Any ideas? I thought that an Unload command did just that and was not actively running that particular form.

Running Excel 2007 in an XP Professional environment.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
If a form is already showing, you cannot send the .Show event again. Place an "On Error Resume Next" prior to where the .Show event is.
 
Upvote 0
If you want a second instance of the userform to be shown you could use this syntax.
Code:
Private Sub btnYes_Click()
    UserForms.Add("frmBenReceipts").Show
End Sub
If there is already frmBenRecipts showing, this will create a second instance of that userform. Both will need to be unloaded to return to "base Excel".
 
Upvote 0
After the btnSubmit on the is clicked, the form disappears (assumed unloaded) but I did notice that when I clicked the No button on my second form, I'm certain I saw both of the forms unloading.

I'll try your suggestion Mike.
 
Upvote 0
Looking at the logic of your set-up, the recusive possibilities might make a whole stack of unloaded frmBenRecipts. You might want to use this testing Sub, to make sure that it returns 0 when you think that it should.

Code:
Sub CountUFs()
    MsgBox Userforms.Count
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,214
Members
449,074
Latest member
cancansova

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