Should I use "Me"?

  • Thread starter Pablo Cardellino
  • Start date
P

Pablo Cardellino

Hi,

to access the values of the form controls I always use just the name of the
control. Is this a good practice or I should better use Me.ControlName? If I
should, why?

Regards,
Pablo
 
G

Gordon Bentley-Mix

Pablo,

If the code is in the UserForm module (and obviously it is or it wouldn't
work otherwise) then you can safely omit the "Me" as the context is assumed
to be the UserForm. The only time I ever use "Me" is when I'm checking to see
if the UserForm is visible before executing some code - usually validation
and formatting code in the Exit event of the control; e.g.:

Private sub txtDate_Exit(ByVal Cancel as MSForms.ReturnBoolean)
If Me.Visible = True Then
If IsDate(txtDate.Value) = False Then
MsgBox "Please enter a valid date.", vbCritical, "Date Error"
Cancel = True
End If
End If
End Sub

In this case a specific context for the Visible property is required -
although thinking about it now, since I instantiate an instance of the
UserForm object, if I declared it as Public, I could probably refer to it
specifically (e.g. If MyForm.Visible = True). Might have to check that out...
--
Cheers!

Gordon Bentley-Mix
Word MVP

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
P

Pablo Cardellino

Thanks, Gordon
your answer was very clear
Regards,

--
Pablo Cardellino
Florianópolis, SC
Brazil

Gordon Bentley-Mix escribió:
 

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