Solved

Not in List (goes to next record after update)

Posted on 2013-06-11
2
471 Views
Last Modified: 2013-06-11
When I apply the following code to not in list (bound form), the code does add new data to table and field but also moves to next record. How do I keep from moving to next record?

Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim Msg As String
Dim NewID As String
'On Error GoTo Err_Provider_NotInList

       ' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub

    ' Confirm that the user wants to add the new Sku.
Msg = "File Status" & space(1) & " '" & NewData & "' does not exist." & vbCr & vbCr
Msg = Msg & "Do you want to create status?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbNo Then
        ' If the user chose not to add a Sku, set the Response
        ' argument to suppress an error message and undo changes.
Me.Undo
Response = acDataErrContinue
    Else
        ' If the user chose to add a new Sku, open a recordset
        ' using the tblSku table.
    Set conn = CurrentProject.AccessConnection
    Set rst = New ADODB.Recordset
    With rst
   .Open "SELECT * FROM TblUSHSFileStatus", conn, adOpenDynamic, adLockOptimistic
   .AddNew
   .Fields("Status").value = NewData
   .Fields("Lastupdate").value = Date
   .Fields("ModifyRecord").value = fOSUserName
  .Update
  ' .Requery
  .Close

MsgBox "File status has been updated"

Response = acDataErrAdded

End With

End If

'Exit_Provider_NotInList:
' '      Exit Sub
Err_Provider_NotInList:
       ' An unexpected error occurred, display the normal error message.
  '     MsgBox Err.Description
       ' Set the Response argument to suppress an error message and undo
       ' changes.
   '    Response = acDataErrContinue
0
Comment
Question by:jbakestull
2 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 39239077
in the design view of the form, hit F4 to view the Property Sheet of the form

select the Other tab

in the Cycle property, set the value to current Record
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39239109
You have remarked out your exit and error processing code, why did you do that?

Aside from the exit/error processing code, I don't see anything here that would cause your main form to move to the next record after processing this code.

Are you sure there isn't something else going on here, after this code is processed?
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now