Compile Error?

  • Thread starter TotallyConfused
  • Start date
T

TotallyConfused

Please help! I compiled my VBA project and I got the following message.
"Compile Error Variable Not Defined". When I clicked on debug it took me to
the following code and highlighted the line frmMyUserform.Show vbModeless.
Can someone please help me understand why. Although my form is working fine.
Is this something I need to fix? If so how? Thank you for any help.

Private Sub UserForm2_Initialize()
Load UserForm2
UserForm2.Show
frmMyUserform.Show vbModeless

Me.FormDate = Format(Date, "mm-dd-yyyy")

End Sub
 
O

OssieMac

Should be

UserForm2.Show vbModeless

delete the line frmMyUserform.Show vbModeless
 
D

Dave Peterson

I'm guessing that this code is behind the userform.

If that's true, then you can't rename the procedure names--use:
Private Sub UserForm_Initialize()

And you don't need these two lines:
Load UserForm2
UserForm2.Show

And I'm still guessing that frmMyUserForm is a different userform--if that's
true, do you really want to show that when userform2 is shown?

If it's the same as the userform that's being loaded (and I guessed wrong), then
remove that line, too.
 
O

OssieMac

I am guilty of not reading and understanding the question well enough. For
that matter I am still not sure I fully understand it now. maybe Dave has
answered your question. However, the following information might also help.

If you have 2 forms open and you want to be able to work on both then they
should both be modeless.

If you show a modal form then all following code stops in the sub that shows
the form until you close the form and then the remaining code in the sub
executes.

Therefore if you open a modal form and in the same sub you try to show
another form after it then the second form will not show until the first one
is closed.

If you open a modeless form then the remaining code in the sub continues to
execute. If the code shows a modal form after the modeless form then both
forms will show but you are stuck on the modal form and cannot focus on the
modeless form until the modal form is closed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top