Results 1 to 5 of 5
  1. #1
    AAAndy is offline Advanced Beginner
    Windows 7 64bit Access 2013 32bit
    Join Date
    Aug 2016
    Posts
    68

    Question Query is updated on closing a form to a different record id


    Query is updated on closing a form to a different record id.

    I have the below form. There are some more textboxes there that are not shown that I also update. I update the form and after updating I click on the form to close it as shown with the mouse in the picture. Another record is then updated which is not wanted. It is updated under intReportID 31 but varReportTitle is changed to the first one in the list, (they are in order alphabetically on the form only). How do I make sure that the form is not saved under a different varReportTitle on exit? How do I make sure its not saved at all? Or if its saved that its saved under the same id, intReportID, and varReportTitle?

    Click image for larger version. 

Name:	issue.jpg 
Views:	7 
Size:	68.9 KB 
ID:	25471

  2. #2
    AAAndy is offline Advanced Beginner
    Windows 7 64bit Access 2013 32bit
    Join Date
    Aug 2016
    Posts
    68
    could it be something in this code

    Code:
    Private Sub cbointReportID_AfterUpdate()
        Dim iVal As Integer
        iVal = Nz(Me.cbointReportID.Value, 0)
        
       
        Dim S As String
        S = "SELECT varReportTitle from dbo_tbl_Custom_Subscription_Subscriptions where intReportID like " & iVal & ""
    
    
        Me.cbovarReportTitle.RowSource = S
        Me.cbovarReportTitle.Requery
        
    End Sub

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Do you have any other code in the form - perhaps in the On Close event?

    Assuming all the form controls have a query field as the control source, I don't see anything that would update any record other than the one currently in the form.

  4. #4
    AAAndy is offline Advanced Beginner
    Windows 7 64bit Access 2013 32bit
    Join Date
    Aug 2016
    Posts
    68
    Quote Originally Posted by John_G View Post
    Do you have any other code in the form - perhaps in the On Close event?

    Assuming all the form controls have a query field as the control source, I don't see anything that would update any record other than the one currently in the form.
    I have nothing in the on close event

    I disabled all my update queries, only select queries are left, and it is still doing it. How do I disable this?

  5. #5
    AAAndy is offline Advanced Beginner
    Windows 7 64bit Access 2013 32bit
    Join Date
    Aug 2016
    Posts
    68
    I added the below code which cancels the automatic update and fixed the issue

    Code:
    Dim SaveFlag As Boolean
    
    
    Private Sub Form_BeforeUpdate(Cancel As Integer)
        If Me.Dirty = True And SaveFlag = False Then
            Me.Undo
        End If
    End Sub
    
    
    Private Sub cmdSave_Click()
        SaveFlag = True
        Me.Dirty = False
        SaveFlag = False
    End Sub

    I also tried below which works but gives error
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
        Me.Undo
        Cancel = True
    End Sub

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

Similar Threads

  1. Replies: 1
    Last Post: 08-06-2016, 10:39 AM
  2. Replies: 11
    Last Post: 04-09-2016, 08:54 PM
  3. Replies: 2
    Last Post: 06-26-2015, 08:05 AM
  4. Replies: 1
    Last Post: 09-17-2013, 11:30 AM
  5. Replies: 2
    Last Post: 04-04-2013, 05:56 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