Results 1 to 2 of 2
  1. #1
    sss8885 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Nov 2015
    Posts
    4

    data corruption help.

    Good morning,

    Recently we have experienced a bout of data corruption. In one of our databases, entries from one of our tables (it's a linked table; sql server) have been deleted. We are not sure why.

    When we started digging through the code we noticed that a lot of it used recordsets. Unfortunately, the recordsets were not closed or set to nothing. I've been taught that is what you are supposed to do, but I was never really taught what would happen if they weren't. Could this be a cause of the data corruption? Has anyone experienced data corruption with recordsets? I'll give an example:



    Private Sub Delete_Required_Items_Click()

    Dim ctlList As Control
    Dim varItem As Variant

    Dim FieldToUpdate As Long
    Dim dbs As Database
    Dim rst As DAO.Recordset
    Dim SelectedDevID As Long
    Dim strSQL As String


    Set ctlList = Me.lstRequiredItems
    SelectedDevID = Me.DevID.Value
    Set dbs = CurrentDb
    strSQL = "SELECT * FROM dbo_DevStatus WHERE DevID = " & SelectedDevID


    ' Open record to update


    Set rst = dbs.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)


    With rst
    ' Find the record to edit
    .FindFirst "[DevID] = " & SelectedDevID


    If Not .NoMatch Then
    ' Loop through selected items and set the required fields in dbo_DevStatus
    For Each varItem In ctlList.ItemsSelected
    ' Begin the edit
    .Edit
    Select Case varItem
    Case 0 To 5
    FieldToUpdate = (varItem * 2) + 12
    Case 6 To 11
    FieldToUpdate = (varItem * 2) + 27
    End Select
    rst.Fields(FieldToUpdate).Value = "N"
    ' Commit the Change
    .Update
    Next varItem
    Else
    MsgBox "Record not found."
    ' Add code to create a new DevStatus record
    End If
    End With

    End Sub


    As you can see, the database nor the recordset close or are set to nothing. The table the recordset connects to wasn't hit, but again, I am not sure what can happen when they don't close. Is it pervasive enough to affect other tables? Thanks in advance.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,945
    It is my understanding that Access/VBA automatically releases variables and closes recordsets when a procedure completes, unless variables are globally declared. Although it is best practice to explicitly close recordsets, I find that where I have neglected to follow through on this I have not experienced any negative impacts.
    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.

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

Similar Threads

  1. Replies: 8
    Last Post: 12-15-2014, 09:41 AM
  2. VBA Module Corruption
    By Jrbeene86 in forum Modules
    Replies: 4
    Last Post: 07-30-2012, 01:28 PM
  3. Data Corruption
    By Pilotwings_64 in forum Access
    Replies: 10
    Last Post: 06-24-2011, 04:25 AM
  4. Corruption nightmare
    By Remster in forum Access
    Replies: 4
    Last Post: 03-25-2011, 06:40 AM
  5. Data Corruption?
    By tdalber in forum Access
    Replies: 2
    Last Post: 02-03-2009, 04:15 PM

Tags for this Thread

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