ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Compile Error? (https://www.excelbanter.com/excel-programming/435664-compile-error.html)

TotallyConfused

Compile Error?
 

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


OssieMac

Compile Error?
 
Should be

UserForm2.Show vbModeless

delete the line frmMyUserform.Show vbModeless

--
Regards,

OssieMac



Dave Peterson

Compile Error?
 
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.

TotallyConfused wrote:

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


--

Dave Peterson

OssieMac

Compile Error?
 
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.

--
Regards,

OssieMac



All times are GMT +1. The time now is 09:57 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com