VBA 'me.ControlName' suddenly not recognized!

Hi,

I use a lot off VBA on an access DB that has been running already for two years now, with continuing developing.

However since a few days it is coming up with problems, not excuting certain VBA codes that have been there for quite a while.

I noticed quite fast that it was every time the 'me.controlname' that 'bugged'. When I replace it with Forms!FormName.ControlName that code works again.

I have used the 'Me.ControlName' quite a lot, so changing them all would be kind off a hasle. Is there a logic explanation for this? And cam I do something about it or do I just have to change all 'Me.ControlName'?? (please not!!)

Thx a lot for your help in advance.

Ciao
bj
BramJanAsked:
Who is Participating?
 
Jim Dettman (Microsoft MVP/ EE MVE)Connect With a Mentor PresidentCommented:
Also, before a re-install, you might want to simply try refreshing the references.

Open a module, click tools/references and check any reference.  Close the MDB and Access, re-open and uncheck the same reference.

Then try a compile and see if you get errors.

Jim.
0
 
nico5038Commented:
Did you check the references for "MISSING" libraries ?

Nic;o)
0
 
BramJanAuthor Commented:
Yep...
No "Missing" libraries.
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
nico5038Commented:
Then I would start with an Access re-install as it looks like the internal "me" reference is lost.

Nic;o)
0
 
BramJanAuthor Commented:
ah..
I guess that can't cause any problems, re-installing Access?
btw, while we are on the subject off installing, any good words regarding Access 2002? Might upgrade it at the same time then.

Thx

btw, Hoe staat het leven trouwens tegenwoordig, zomervakantie in zicht?
0
 
BramJanAuthor Commented:
ah..
I guess that can't cause any problems, re-installing Access?
btw, while we are on the subject off installing, any good words regarding Access 2002? Might upgrade it at the same time then.

Thx

btw, Hoe staat het leven trouwens tegenwoordig, zomervakantie in zicht?
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
I'm not sure how you managed to do that, but 'ControlName' is not a valid property of a form.


Jim.
0
 
John Mc HaleForensic Computer Examiner, Analyst/Programmer & Database ArchitectCommented:
Is it possible that someone else is "playing around" with the name of controls on Forms.

Personally I prefer to use VBA code blocks like ...


Sub AnyButton_Click()

With Me

   .AnyControl.Caption = "Whatever"

End With

End Sub

This way, the Object Browser window will pop up, and you will know soon enough if a controls with that name exists on the Form.

HTH
0
 
archeryCommented:
Just a stab-in-the-dark here.

You didn't by any chance take the code that was (originally) behind the form itself, and put it into a NEW stand-alone module, did you.

The Me. ONLY works within code that is ACTUALLY within a form/report itself as it is (actually) referring to the current form/report with the focus.

(I did this once myself and suddenyl started getting runtime errors because I hadn't re-compiled my application first to check for errors, as I assumed (as I had made no ACTUAL code changes that it would work the same way, forgetting about the Me. reference).

0
 
BramJanAuthor Commented:
Hi,
Thx to all for your comments.
JDettman, i didn't mean 'ControlName' as a property on a form, but just 'a' controlname like CompanyName, which would make me.CompanyName, which 'is' a control on my form.

Your remark regarding refreshing, seems to done the job, since I tested the me.reference and it 'seemed' to work.

However I would like to leave the question open for 1 or 2 days to see if it doesn't occur again and if I'm right that it is ok now. since it is quite a big db and not possible for me to go though all the forms.

Thx again for your help and I'll be back, please don't hesitate to leave any other comments.

Ciao
bj
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
<<JDettman, i didn't mean 'ControlName' as a property on a form, but just 'a' controlname like CompanyName, which would make me.CompanyName, which 'is' a control on my form.
>>

  That makes more sense.  I always forget that from A97 up, that controls can be referenced like a property.  Old Habits die hard and I still use ! for object references and . for properties only.  Had me thinking in the wrong direction.  

<<Your remark regarding refreshing, seems to done the job, since I tested the me.reference and it 'seemed' to work.>>

 Yes, the references are not always marked "MISSING" or "BROKEN" even though they really are not correct.  The check/uncheck forces Access to refresh the references collection and fix any problems.  Keep it in mind anytime you start to have problems with built-in functions or properties/methods.

Jim.
0
 
BramJanAuthor Commented:
Haven't had the problems anymore since i did this. So I guess that was the solution. I still think that Bill Gates should be notified of this, because it is again weird bug  that doesn't make any sence, which i encounter more and more these days, those unexplainable bugs.

but jim, THX!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.