variable not defined error for field that exists?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BarksWorseThan
    New Member
    • Nov 2011
    • 5

    #16
    I know these posts are from more than a year ago, but just want to say/clarify: I have run into this same problem, and what I notice is that the fields that are throwing the "Variable not defined" error are either fields whose names I changed recently in the table definition or new fields that I recently added to the table.

    In the form design view, the Field List and the drop-down for the Control Source for a control reflect the current table design; but VBA seems to have a stale copy of the form's recordsource schema. So far I have had no success finding a way to refresh/update VBA's "awareness" of the recordsource's current field names... Any ideas?

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #17
      Oh wow!

      I didn't see this before (So I won't *slap* BarksWorseThan for hijacking the thread - but I will say if you want a question answered then the way to do that is to post a question thread).

      Melissa, there are a number of confusions in here. Some of which Mario has helped with, but others he's missed.

      First off, it's best to understand the differences between variables, fields and controls. My guess (after the first post and hasn't changed since) is that you have a control missing for dpr_work. Either mis-spelled or just called something completely different - like Check29 or something. The field is probably fine, but you never renamed the control.

      Forms actually can have Fields, but these are underlying and what you see on forms are controls (which may be bound to the fields). It gets more complicated from there, but I expect it's resolvable from that anyway. let us know how you get on ;-)

      Comment

      • BarksWorseThan
        New Member
        • Nov 2011
        • 5

        #18
        NeoPa -- a pleasant surprise to get a quick response! I was not really expecting much from my post here... was more interested in trying to clarify for others who may land here that the problem is real and probably NOT related (as you propose) to confusion between fields, variables, and controls.

        At least in my case, I name my controls differently from the fields that are used as the control source specifically to avoid confusion when coding between the field and the control; likewise, I have yet a third convention for naming variables. So, for example, field "TractSubCo de" is the control source for control "cboTractSubCod e", and if I wanted some variable referring to the TractSubCode I would name it strTractSubCode .

        Now, in my case, I used to have a field (in a *linked* table, in case that's important) called simply "TractSub", which used to be the Control Source for the control cboTractSub. When I renamed the column to "TractSubCo de" (for semantic reasons), I changed the control source for the drop-down, and also renamed the control to "cboTractSubCod e".

        In VBA, however, I cannot refer to "TractSubCo de", else I get the "variable not defined" error. If I type Me. Intellisense presents me with the old list of fields (among the many other options)... so "TractSub" is on the list even though it no longer exists in the table. Also, some new fields that I have added to the table are not present via Intellisense, and if I try to use them I get the "variable not defined" error, even though I can see the new and re-named fields correctly when I'm in Form Design mode.

        So it would appear to be -- at least in my case, but I suspect also in the OP's case -- some kind of "stale" schema or metadata info on the VBA side of things. The Form Design sees all of the changes and additions to the table, but in VBA it's stuck on the table fields as they were when I first created the form.

        Hope this helps to clarify where the problem lies. Thanks for your help.

        Comment

        • BarksWorseThan
          New Member
          • Nov 2011
          • 5

          #19
          Sorry for the typo on your id, NeoPa...

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32633

            #20
            Originally posted by BarksWorseThan
            BarksWorseThan:
            At least in my case,
            Herein lies the rub of course.

            Though you clearly describe your situation, the thread is related to the situation of the OP (AccessIdiot as she refers to herself but I happen to know she is overly self-deprecating in that). I cannot, nor should I (You sound intelligent enough to appreciate why without detailed explanation), get involved with your particulars in this thread as that would hijack it away from the OP.

            If you'd like to raise this issue yourself, in a separate thread, I'll be happy to deal with it in greater detail.

            PS. It's not unlikely that all such posts, unrelated directly to the OP's specific problem, will be removed as hijacks, but I won't do so myself. I'm fussy, but I can see benefit in this, at least for now (Others may be fussier though ;-)).

            PS. No problem with the ID. I didn't even see it and I find people actually getting it right is a rarity. Being fussy though, I like it when they do :-)

            Comment

            Working...