Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369

    Question Unanswered: VBA (reference?): why does me.x change to [x]?

    What may cause

    Me.txt3 = Me.txt1 / Me.txt2

    to change to

    Me.txt3 = [txt1] / [txt2]

    either between close/reopen or after a compile, or after a compact?

    This happens for some of the OnChange or AfterUpdate events on some of my form CONTROLS. Unsure if it has happened to other events etc.

    It happens only sometimes. It is fairly rare and I have not dug into it. Note that the initial part, "Me.txt3 =" does not seem to change, only the part after "="...

    D.
    Win-XP pro, Access 2002, ADO 2.7, DAO 3.6. English versions of apps/OS.

  2. #2
    Join Date
    Jun 2004
    Posts
    55
    Doesn't really matter much.

    Me.txt3 = Me.txt1/Me.txt2

    Is the same as:

    Me.txt3 = [txt1]/[txt2]

    Is the same as

    [txt3] = [txt1]/[txt2]

    Is the same as

    txt3 = txt1/txt2

    They're just differents ways for writing it. The program is probably just simplifiying it for itself.

  3. #3
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369

    Question

    It seems that the form

    Me.txt3 = [txt1]/[txt2]

    does not work/calculate here...
    (and that is the one it is changed to automatically...)
    Any way to either avoid this, or affect which "way" it is corrected?
    Is this affected by any of the entries in the VBE References list? For example Office 10 library, which I have checked? If it is that one, what do I "loose"/risk if I disable it?

    D.
    Win-XP pro, Access 2002, ADO 2.7, DAO 3.6. English versions of apps/OS.

  4. #4
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Use must use Brackets when your Textbox's name contains spaces i.e

    [Text Sum] = Text1 + Tetxt2
    OR
    [Text Sum] = [Text1] + [Tetxt2]
    OR
    Me.[Text Sum] = Me.[Text1] + Me.[Tetxt2]

    But you can not say

    Text Sum = Text1 + Tetxt2

  5. #5
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369
    Quote Originally Posted by hammbakka
    Use must use Brackets when your Textbox's name contains spaces
    OK. However, none of my control or field names contain spaces, ever. I always use underscores if I want "a space".

    What puzzles me is that it changes only some places, not all, and only AFTER the = sign, not for the preceding "Me.something = " ...

    I also wonder if it is possible to stop Access from auto-changing this?

    D.
    Win-XP pro, Access 2002, ADO 2.7, DAO 3.6. English versions of apps/OS.

  6. #6
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    If you type Me then the point, do you get the window containing all the properties and events of the Form?

  7. #7
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369
    yes, I always use that method to avoid mistyping the field names. No problem with that functionality in this db.
    Win-XP pro, Access 2002, ADO 2.7, DAO 3.6. English versions of apps/OS.

  8. #8
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    Perhaps the VBA compiler is trying to "fix" your code. As to what triggers it, we'll probably never know, unless we could step through the program that performs the compile (something I would never want to see).

    Several possible "fixes" to help prevent Access from trying to "fix" code that isn't broken:

    1. Put the arguments in the funtion in ( )
    Me.txt3 = (Me.txt1)/(Me.txt2)

    2. Use variables for you arguments
    varV1 = Me.txt2
    varV2 = Me.txt3
    Me.txt1 = varV1 / varV2


    3. Use a different form of "referencing" the controls
    Me("txt1") = Me("txt2") / Me("txt3")

    Good luck!

  9. #9
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369
    Thanks, will consider using variables more, when appliccable.

    D.
    Win-XP pro, Access 2002, ADO 2.7, DAO 3.6. English versions of apps/OS.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •