Results 1 to 6 of 6
  1. #1
    Middlemarch is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2015
    Posts
    479

    Update fails - looking for fix

    My Form_FormMode7 has a query on my table. as the Record Source


    A control txtBComment on the Form has it's control source set to a field from the property box dropdown list.
    A second text box copies text to that control via after update event

    Code:
    Private Sub BComment_AfterUpdate()
    txtBComment = Replace(Nz(BComment), vbCrLf, vbLf)
    With Form_FormMode7
            If .Dirty Then .Dirty = False
    End With
    End Sub
    Why does this not work reliably? Sometimes the table is updated but often not. I have to double check it every time.
    The code runs without error. I added the .Dirty believing it forced a save, but it made no difference.

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Have you tried a breakpoint to see if the afterupdate event always fires?
    Here's some code to deal with possible nulls in an alternate fashion:

    Code:
    Private Sub BComment_AfterUpdate()
    If Len(BComment & vbnullstring) > 0 then
        txtBComment = Replace(BComment, vbCrLf, vbLf)
        Me.Dirty = False
    EndIf
    End Sub

  3. #3
    Middlemarch is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2015
    Posts
    479
    Thanks dave yes the after updater event was NOT running.
    I added a different backcolor to a label to prove it.

    I wonder what Access considers an update? I would have thought no text to some text would always fire it.

  4. #4
    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
    Quote Originally Posted by Middlemarch View Post

    ...A second text box copies text to that control via after update event...

    ...I would have thought no text to some text would always fire it...
    A Control's AfterUpdate event does not fire if the Control is being populated by code...only if it is physically (i.e. via keyboard or thru a copy & paste operation)...and I'm assuming, from the first statement, above, that you're doing this with code:

    To get AfterUpdate to fire, when using code to populate the Control, you have to Call it after you populate it:

    Me.ControlName = "Whatever"
    Call NName_AfterUpdate


    Linq ;0)>

  5. #5
    Middlemarch is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2015
    Posts
    479
    Thanks Linq, didn't know that. All OK now!

  6. #6
    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
    Glad we could help!

    Good luck with your project!

    Linq ;0)>

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

Similar Threads

  1. Update query with replace function fails
    By Keven in forum Queries
    Replies: 5
    Last Post: 07-11-2016, 08:59 AM
  2. Replies: 1
    Last Post: 05-08-2013, 07:08 PM
  3. ADO Update fails after Form Refresh
    By EddieN1 in forum Programming
    Replies: 4
    Last Post: 12-19-2011, 08:07 PM
  4. Requery fails
    By Dega in forum Forms
    Replies: 3
    Last Post: 09-28-2010, 08:35 AM
  5. Printing form: image fails to update
    By stellar0645 in forum Forms
    Replies: 6
    Last Post: 02-04-2010, 11:41 AM

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