Run dlookup only ONCE at form load

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gilberto
    New Member
    • Aug 2007
    • 135

    Run dlookup only ONCE at form load

    Hello,

    I have a form with a couple of text boxes with dlookup as control source. They work alright the problem is that every time i navigate across records the lookup runs again as i can clearly see how the text disappears and appears again...taking some time...

    Is there a way to run the lookup ONLY when the form loads and to keep them "static" while working on the form???

    Thanks,
    Gilberto
  • dima69
    Recognized Expert New Member
    • Sep 2006
    • 181

    #2
    Originally posted by Gilberto
    Hello,

    I have a form with a couple of text boxes with dlookup as control source. They work alright the problem is that every time i navigate across records the lookup runs again as i can clearly see how the text disappears and appears again...taking some time...

    Is there a way to run the lookup ONLY when the form loads and to keep them "static" while working on the form???

    Thanks,
    Gilberto
    In the form module, create your own functions to get dlookup value, then set control sources of the textboxes to that functions.
    Each function will use static variable to hold the required value, so you have to use dlookup only ones within each function.
    [CODE=vb]Function MyLookup1() as Variant
    Static V1 as Variant, SetFlag as Boolean
    If SetFlag = FALSE then
    SetFlag = TRUE
    V1 = DLookup(WhatEve r ...)
    End If
    MyLookup1 = V1
    End Function[/CODE]

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

      #3
      Usually when you want something to run when the form loads you place it in Sub Form_Load()!

      Where does the code currently reside?

      What are you looking up with DLookup that you want present on all records?

      Linq ;0)>

      Comment

      • Gilberto
        New Member
        • Aug 2007
        • 135

        #4
        Thanks for your replies.

        I changed the text boxes to UNBOUD and in the form LOAD event i entered simple text such as: me.level1label. value = dlookup(")....a nd it works great. Now the boxes only load with the form and not every time the user changes records.

        im still very new with access and writing code and was wondering whats the use or difference between what i did and using "functions" such the one suggested above in the reply above???

        Thanks,
        Gilberto

        Comment

        • dima69
          Recognized Expert New Member
          • Sep 2006
          • 181

          #5
          Originally posted by Gilberto
          Thanks for your replies.

          I changed the text boxes to UNBOUD and in the form LOAD event i entered simple text such as: me.level1label. value = dlookup(")....a nd it works great. Now the boxes only load with the form and not every time the user changes records.

          im still very new with access and writing code and was wondering whats the use or difference between what i did and using "functions" such the one suggested above in the reply above???

          Thanks,
          Gilberto
          The solution suggested by Linq is the most simple and logical, I guess :)
          However, it has its drawbacks. If you put all the DLookup's in the Form Load event, it will (naturally) slow down the form load. On the other hand, the functions within control source will execute asinchronously, thus not slowing form loading (but, eventually, taking the same time).

          Comment

          Working...