Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking for edit on form

Status
Not open for further replies.

glgcag

MIS
Apr 25, 2001
160
US
I'm using unbound forms and I'm having some difficulty trying to check for edits to a form and then post those edits before going to the next record that the user selects.

First, here's the code I'm using to check for edits:

Code:
Private Function CheckForEdit() As Boolean
On Error GoTo ErrHere
    Dim bEdit As Boolean
    Dim rst As ADODB.Recordset
    Dim sSQL As String
    Dim lPID As Long
    Dim ctl As Control
    
    For Each ctl In Me.pgMain.Controls
        If (ctl.ControlType = acTextBox) Then
            Debug.Print ctl.Name
            If ctl.Visible = True And ctl.Tag <> ctl.Value Then
                Debug.Print ctl.Tag
                Debug.Print ctl.Value
                bEdit = True
            End If
        ElseIf (ctl.ControlType = acCheckBox) Then
            Debug.Print ctl.Name
            If ctl.Visible = True And ctl.Tag <> ctl.Value Then
                bEdit = True
            End If
        End If
        
    Next ctl
    
    If Left(Me.txtNotes.Tag, 2047) <> Left(Me.txtNotes, 2047) Then
        bEdit = True
    End If

    If bEdit = True Then
    'process edit
        lPID = Me.cmbProject.Column(0)
        sSQL = "SELECT * FROM [soundtrack table] WHERE SoundtrackID = " & lPID & ";"
        Set rst = New ADODB.Recordset
        rst.Open sSQL, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
        With rst
            ![Score?] = Me.chkScore
            ![Song?] = Me.chkSong
            !NonGSA = Me.chkNonGSA
            !NoSndtrkRel = Me.chkNoSndtrkRel
            !ArtProdDoneTracking = Me.chkArtProdDone
            !MechDoneTracking = Me.chkMechDone
            ![Film Company] = Me.txtFilmCompany
            !FilmReleaseDate = Me.txtFilmReleaseDate
            ![Record Label] = Me.txtRecordLabel
            !SoundtrackReleaseDate = Me.txtSoundtrackReleaseDate
            !SoundscanDomesticUnits = Me.txtSoundscanDomesticUnits
            !SoundscanReportDate = Me.txtSoundscanReportDate
            !TotalCuts = Me.txtTotalCuts
            !ArtistCuts = Me.txtArtistCuts
            !ProducerCuts = Me.txtProducerCuts
            !ArtistProRataCuts = Me.txtArtistProRataCuts
            !ProducerProRataCuts = Me.txtProducerProRataCuts
            !Notes = Me.txtNotes
            !ProjectComPct = Me.txtProjectCommPct
            !PreTracking = Me.chkPreTracking
            !ArtProdDoneTracking = Me.chkArtProdDone
            !MechDoneTracking = Me.chkMechDone
            !PendingResearch = Me.chkPendingResearch
            .Update
            .Close
        End With
        CheckForEdit = True
    Else
        CheckForEdit = False
    End If
    
ExitHere:
    Exit Function
ErrHere:
    MsgBox "Error: " & Err.Number & " --- " & Err.Description, vbCritical, "Error"
    CheckForEdit = False
    Resume ExitHere
End Function

I put this code in the Before Update event of the combo box users select to move to the desired record. In the After Update event of the same combo box, I clear all the controls and load the new record. For some reason when I check for edit, the old record is being written to the new record the user is going to. Strange, to say the least.

Should I call the CheckForEdit function somewhere else? I need to check for edits prior to getting clearing the controls somehow, but it's acting VERY strange!

Any help is appreciated!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top