• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA Unload Me

Hi,

I am new to VB and trying to teach myself


I have some questions


when writing code to cancel a form we use:


Private Sub cmdCancel_Click()

Unload Me

End Sub


What does Me mean??


Also in the following code what does Me do?


Private Sub cmdOK_Click()

If Me.txtFirstName.Value = "" Then

MsgBox "Please enter a First Name.", vbExclamation, "Staff Expenses"

Me.txtFirstName.SetFocus

Exit Sub

End If

End Sub


Thank you!
 
Me is the container that owns the code

So in the two cases you gave it will be the userform that you have used


In the second case it looks like you have renamed a text box to TxtFirstname

Which belongs to a Userform which can be called Me
 
me refers to the active userform. so
Code:
unload me unloads the userform


[code]me.txtfirstname refers to the object named txtfirstname in the active userform (most likely a textbox)


say the userform was called my_userform and my_textbox was a text box in it


you could write my_userform.my_textbox
to refer to it (which is what you would do if the userform wasn't active)


However if the userform is active you can simply write me.my_textbox[/code] to refer to it
 
Correct. It's a recognized object in VBA syntax, always referring to container where code resides. So, legit to use in Sheet modules, UserForms, not legit in a regular Module.
 
Back
Top