Results 1 to 3 of 3
  1. #1
    XenoZephyr is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    16

    Question My last update code and searching for a new record code are not working together

    I have code that puts in a date for when the record is last updated:



    Private Sub Form_BeforeUpdate(Cancel As Integer)
    LastUpdated = Date
    End Sub

    It works as long as after I make any change I go to a different record using the navigation buttons at the bottom of the form.

    However, we have a txtbox in the header that we use to search for records by last name, and if I make a change and then use our search box to go to a new record, I get an error when I use that BeforeUpdate code above. The Error code says "Update or CancelUpdate without Addnew or Edit"

    This is the search code that I am using. It is something that I copied off of online so I'm not sure it is the best but it was simple and it works:

    With Me.RecordsetClone
    .FindNext "[Last Name]=""" & strSearch & """"
    If .NoMatch Then
    Beep
    Else
    Me.Bookmark = .Bookmark
    End If
    End With

    With my VERY basic understanding it seems that what is happening is that
    1) I make a change
    2) Before it updates it changes the Lastupdated field to today's date
    3) (Still before updating) I do a search for a new last name and try to go there
    4) It doesn't like that because the last record wasn't done updating...

    So, any ideas on how to fix this? Is this were I should requery or something like that I assume?

    Thanks

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    48,682
    Commit the record before proceeding with search

    Maybe:

    If Me.Dirty Then Me.Dirty = False

    or

    DoCmd.RunCommand acCmdSaveRecord
    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
    XenoZephyr is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    16
    Thanks for the quick reply! It was the .Dirty property that I was not familiar with. So I added this code
    if Me.Dirty then Me.Refresh

    and it works fine now!
    Thanks again

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

Similar Threads

  1. Replies: 1
    Last Post: 08-09-2012, 04:19 PM
  2. Replies: 12
    Last Post: 03-14-2012, 10:54 AM
  3. VBA Code not working how it Should
    By Juan4412 in forum Programming
    Replies: 7
    Last Post: 12-07-2010, 01:59 PM
  4. VB code not working
    By cwwaicw311 in forum Programming
    Replies: 17
    Last Post: 04-26-2010, 07:02 PM
  5. Replies: 4
    Last Post: 05-12-2009, 01: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
  •  
Tech Forums: Microsoft Office Forums