Compile Error "Argument not Optional" from userform

High Plains Grifter

Board Regular
Joined
Mar 9, 2010
Messages
129
Hi people

I am using UerForms majorly for the first time, and I am having a bit of a mistifying problem...

The first userform takes and input and gives three choices: Exit, Use the Input, Manual Search.
Exit has the following code:
Code:
Private Sub BRefExit_Click()
Unload Me
End Sub
and that works fine, but the Manual Search button has this code:
Code:
Private Sub BRefSearch_Click()
Unload.me
Selecta.Show
End Sub
This is not so very different, but returns this error: Compile Error: Argument not Optional, and selects Unload.Me, then when I click ok, it highlights the top line. I tried silly things like this (which I probably should have guessed would not work):
Code:
Private Sub BRefSearch_Click()
    If 1 = 1 Then
        Unload.Me
    Else
        Unload Me
    End If
Selecta.Show
End Sub
but nothing seems to correct it.
Why has Excel turned on me like this?

Thanks for reading this, and any answers gratefully received (particularly by my fast disintegrating teeth)
Mark
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Code:
Private Sub BRefSearch_Click()
    If 1 = 1 Then
        Unload.Me
    Else
        Unload Me
    End If
Selecta.Show
End Sub
If 1 = 1?
Well, 1 = 1 so it will unload unless you put something else into the equation...
Code:
    If Range("A1") = "1" Then
        Unload Me
    Else
        Unload Me
        Userform2.Show
    End If




Not sure, but I think the forms name "Selecta" is part of the problem. Try to renaming it and then use something like:
Code:
Sub But_Close()
    Unload Me
    NewName.Show
End Sub
 
Last edited:
Upvote 0
This will unload the userform:
Code:
Unload Me

This will do nothing but crash your program:
Code:
Unload.Me

It's a surprise you hadn't figured that out yet ... ;) The unload syntax is different than the usual. I remember being puzzled by it myself and posting a similar question about two years ago or so. As matter of technicalities, it seems the form is not unloaded by a method of its own (a "Me" method) but by a vba command. Something along those lines anyway.

Edit:
Just noticing in the last post attention to the SelectA.Show line ... You may find that it crashes because you can't (I don't think) run command from an object you've just destroyed. So you may have more errors to deal with ...
 
Last edited:
Upvote 0
Oh my word... Thank you - well spotted! I am just off to bed, and I can sleep easy now I know that I have been an idiot again, and Excel is not out to get me (a scary prospect in anyone's workbook).

Thanks a lot :¬D
apologies for wasting your time - that had got me totally stumped.
 
Upvote 0
This will do nothing but crash your program:
Code:
Unload.Me
Completely missed Unload.Me, sorry.

That caused the first part of the problem:
Code:
    If 1 = 1 Then
        Unload.Me <-- here
    Else
        Unload Me <-- Here you got it right
                  <-- But since 1 = 1 you'll never got here
    End If
Selecta.Show
End Sub

Edit:
Just noticing in the last post attention to the SelectA.Show line ... You may find that it crashes because you can't (I don't think) run command from an object you've just destroyed. So you may have more errors to deal with ...
Code:
Unload.Me


Meaning this?
Code:
       Unload Me
        Userform2.Show
I use that a lot and it works fine for me. I assume that it reads all code til the end of the sub, or am I wrong?
 
Upvote 0
Meaning this?
Code:

Unload Me
Userform2.Show

I use that a lot and it works fine for me. I assume that it reads all code til the end of the sub, or am I wrong?

Yes - but it sounds like my worry is unfounded - so it must be that the remaining code in the procedure does execute, before the form is actually destroyed. Good to know.
 
Upvote 0
Hello!

I learing HMI/SCADA iFIX. I made a user form. The problem occurs when i call user form named Modify.

Private Sub CommandButton3_Click()


Modify.Show

End Sub

After I click CommandButton3 program display me error. Compile error: Agrument not optional!

How to fix this error?
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,369
Members
449,080
Latest member
Armadillos

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