Results 1 to 7 of 7
  1. #1
    Steven19 is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2020
    Location
    London
    Posts
    110

    Afterupdate DefaultValue not working

    To Save time I have:



    Private Sub VatNumber_AfterUpdate()Me.VatNumber.DefaultValue = """" & Me.VatNumber.Value & """"
    End Sub

    This is in the Afterupdate of the control VatNumber

    So when I click the button on the page:
    Private Sub btnReviewVat_Click()
    DoCmd.GoToRecord , , acNewRec
    End Sub

    I expect the field VatNumber to have the same value as the previous record so that I may adapt the associated fields accordingly.

    This is all my code, but its not working, any ideas of what is stopping the new record from pulling the data through from the old record?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Code works for me.

    What does 'not working' mean - error message, wrong result, nothing happens?
    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
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Agree with June -- need some context.

    I expect the field VatNumber to have the same value as the previous record
    Please explain why you think this.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    If you do not update VATnumber, that event does not run I believe?
    Have you set a breakpoint and walked though your code?
    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

  5. #5
    Steven19 is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2020
    Location
    London
    Posts
    110
    Hi June
    For me nothing happens.
    Regards

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Respond to gasman's post. Have you actually typed an entry in the control and committed the input with Enter or Tab to trigger the event?
    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.

  7. #7
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Assuming that the posted code

    Private Sub VatNumber_AfterUpdate()Me.VatNumber.DefaultValue = """" & Me.VatNumber.Value & """"
    End Sub

    is the result of your not formatting your post using the code tags (# on the bar at the top) and actually reads

    Code:
    Private Sub VatNumber_AfterUpdate()
      Me.VatNumber.DefaultValue = """" & Me.VatNumber.Value & """"
    End Sub


    there's no reason that this shouldn't work...with the caveat that it will only work until you either enter a new VatNumber, or Close the Form.

    Entering a VatNumber...then Closing the Form...and then coming back at a later time to go to a New Record, will not bring the desired Default Value from the last Record entered.

    You can, however, brings this number forward, after closing then re-opening the Form, by using a standard shortcut of entering the Control then hitting <Ctrl> + <">.

    Linq ;0)>

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

Similar Threads

  1. .DefaultValue works only half the time.
    By PeakH in forum Forms
    Replies: 1
    Last Post: 10-20-2017, 04:14 PM
  2. .defaultvalue isn't working with a date
    By snipe in forum Forms
    Replies: 1
    Last Post: 10-21-2014, 11:06 AM
  3. AfterUpdate/OnChange not working
    By ccordner in forum Forms
    Replies: 1
    Last Post: 02-08-2012, 11:58 AM
  4. Replies: 3
    Last Post: 07-08-2010, 01:47 PM
  5. Replies: 2
    Last Post: 11-04-2009, 09:45 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