Results 1 to 5 of 5
  1. #1
    DCV0204 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    85

    Next Record after update

    Ok, I have tried to figure this out with no luck. I either get Runtime Error 2105 or 13.


    I have a bound textbox "ReviewedBy" on a from with a query "InitialPrescriberReview" recordsource, I am trying to on AfterUpdate (ReviewedBy) ask a question as to whether to save changes or not.
    If yes, requery the record set and go to the next record.
    If no, remove what was entered into "ReviewedBy" and stay on the same record to make changes.

    My code works unless I select "No" and then update the form enter the reviewedBy and it errors on the acnext.
    Here is my code (I left some of the things I have tried as comments.)

    Private Sub ReviewedBy_AfterUpdate()
    Dim Msg, Style, Title
    Msg = "Are you sure you have finished the review of this prescriber?" & vbNewLine & vbNewLine & " Yes, will remove this prescriber from the form" & vbNewLine & " No, will let you update additional information for the prescriber."
    Style = vbYesNo + vbCritical + vbDefaultButton1
    Title = "Critical"
    Response = MsgBox(Msg, Style, Title)
    If Response = vbYes Then 'User chose Yes.
    MyString = "Yes"


    Me.cmdnxt.SetFocus
    Me.ReviewedBy.Enabled = False
    Me.Form.Requery
    Me.Form.SetFocus
    DoCmd.GoToRecord , , acNext
    DoCmd.GoToControl "iC"
    'DoCmd.GoToRecord "InitialPrescriberReview", , acNext
    'Me.Form.SetFocus
    Me.Requery



    'DoCmd.GoToRecord acActiveDataObject, , acNext


    Else 'User chose No.
    'Me.Refresh
    Me.Undo
    Me.ReviewedBy = Null
    Me.Form.SetFocus
    Me.Requery
    'Me.iC.SetFocus
    'DoCmd.GoToRecord acActiveDataObject, , acNext
    'DoCmd.GoToRecord acActiveDataObject, , acPrevious
    End If
    End Sub

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Maybe place your code in the BeforeUpdate event and use Cancel = True ? I would be careful employing Undo perhaps Cancel = True will suffice.

  3. #3
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332
    Since you are binding the form to the data, updates will happen unless you cancel them in the "Before Update" event as ItsMe suggested.

    I also don't see any need to requery if you have multiple records in your form. You should just move on to the next record. A requery should only happen if your code is changing the data behind the form and in general this is a no no anyway.

    Personally, I have found myself avoiding binding forms to queries more and more. They are a neat RAD feature of Access but it has some downsides. If you instead handle your CRUD through SQL queries and value setting from recordsets (which is what you do in VB.NET), you will have more flexibility in user output/input and record navigation.

    It has been a valuable step in my learning process as I move away from Access development and into the more powerful languages like VB.NET, C#, PHP, and Javascript.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Yes, use the BeforeUpdate event. Cancel = True will abort the record commitment but probably still want to Undo the control input.
    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.

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by June7 View Post
    ... probably still want to Undo the control input.
    Perhaps I am just being superstitious but I prefer to assign whatever the default value is back to the field via the control.

    me.ReviewedBy = ""
    or
    ReviewedBy = 0
    or null, etc

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

Similar Threads

  1. Replies: 4
    Last Post: 12-14-2012, 06:33 PM
  2. Update Record.
    By maawar in forum Access
    Replies: 0
    Last Post: 02-04-2012, 05:09 AM
  3. Update Particular Record
    By anwaar in forum Forms
    Replies: 1
    Last Post: 08-31-2011, 11:05 AM
  4. same form for new and update record
    By lizu in forum Forms
    Replies: 3
    Last Post: 06-20-2011, 08:34 AM
  5. trying to update a record
    By mrsgwen in forum Access
    Replies: 1
    Last Post: 02-02-2011, 10:35 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