Results 1 to 9 of 9
  1. #1
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658

    Form doesn't repaint data of changed field

    I've got a form, on it is a field that I calculate a value for.


    If the field is null, this code runs onenter:

    Code:
    Private Sub tbxm_EntityCd_Enter()
      If IsNull(Me!EntityCd) Then
        Me!EntityCd = fGetSeqId("tbl_39_Entity", "EntityCd", "sTestTwg", True, True)
        Me.Repaint
      End If
    End Sub
    After it runs, the form textbox doesn't show the value.
    If I press tab, then it shows correctly as it moves to the next textbox.

    Why isn't repaint repainting the form for this procedure?
    (I don't want to refresh or requery as the record isn't ready to save yet.)
    Is there a better event to load a value into for a field on a form?

    Thanks

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Is EntityCd a field in table you want to populate? Why save calculated value? Why not put function call in textbox ControlSource?

    Probably doesn't show because data is not committed to field until leaving textbox. If textbox has same name as field, try Me. instead of Me!. I always name control different from field, like tbxEntity.

    Repaint should not be needed.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658

    Some additional info

    Quote Originally Posted by June7 View Post
    Is EntityCd a field in table you want to populate? Why save calculated value? Why not put function call in textbox ControlSource?
    Let's call it more of a calculated default value. The user can stay with it or change it, as suits their needs.

    Probably doesn't show because data is not committed to field until leaving textbox. If textbox has same name as field, try Me. instead of Me!.
    I would like to show the default value when entering and before leaving the textbox, thus giving the user a chance to see what it is.
    I often have a problem with Me! working (compiling), and then, with some other change, not working, and then Me. will compile. I've yet to figure out that little stumper.

    I always name control different from field, like tbxEntity.
    Like this? (This is what I already had)
    Click image for larger version. 

Name:	221007-2.jpg 
Views:	16 
Size:	29.9 KB 
ID:	48870

    Repaint should not be needed.
    Under what condition in this case?
    Form.Repaint method (Access) | Microsoft Learn

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    I often have a problem with Me! working (compiling), and then, with some other change, not working, and then Me. will compile. I've yet to figure out that little stumper
    The '!' is late binding, it is used when the value is not known at compile time. The '.' is early bound and means the object is known at compile time. If not found the compile fails. So if you use '!' the compiler won't fail, but it will fail at runtime if the object is not found.

    Always better to use '.' as a) this will pick up on missing objects and b) enables the use of intellisense because the objects are known and listed.

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    And try to use Me.Recalc instead of Me.Repaint and see what you get.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    I figured it out. I'm still getting up to speed on the black box which is Access.
    I changed Me!EntityCd to Me!tbxm_EntityCd and it works, even without the repaint. (See posts 1 & 3)

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Hardly a black box issue.?
    With any programming language, you have to get the names correct.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    I changed Me!EntityCd to Me!tbxm_EntityCd
    And if you typed Me.tb intellisense would have filled it in for you. no spelling or reference mistakes.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  9. #9
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    I'm still getting up to speed on the black box which is Access.
    since you want to avoid most of what access offers, I guess it will remain a black box

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 08-20-2020, 08:11 AM
  2. Replies: 4
    Last Post: 08-30-2017, 07:10 AM
  3. Default value doesn't update when date is changed
    By TheHarleygirl2005 in forum Programming
    Replies: 4
    Last Post: 08-30-2013, 05:57 PM
  4. Replies: 3
    Last Post: 06-19-2013, 02:39 PM
  5. Replies: 4
    Last Post: 12-16-2010, 03:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums