Link to home
Start Free TrialLog in
Avatar of gsilouisvilleic
gsilouisvilleicFlag for United States of America

asked on

Troubleshooting Save_Record_Click() VBA

I have a form in which I'm trying to save data to a table.  I have similar code that I  used for another form in the same database which saves to a different table that works perfectly, but this code is not saving or resetting any of the fields.  Is there something I'm missing that needs to be changed?  Thank you in advance for your help.

Thanks,
Cassie


Private Sub B_Save_Locked_Location_Audit_Record_Click()

If Nz(Me.T_LockedBy, "") = "" Then
    MsgBox "Please Enter a Name"
    Me.T_LockedBy.SetFocus
    Exit Sub
Else
If Nz(Me.T_LockedLocation, "") = "" Then
    MsgBox "Please Enter a Location"
    Me.T_LockedLocation.SetFocus
    Exit Sub
Else
If Nz(Me.T_TypeofSkip, "") = "" Then
    MsgBox "Please Select Type of Skip"
    Me.T_TypeofSkip.SetFocus
    Exit Sub
Else
If Nz(Me.T_ReasonforSkip, "") = "" Then
    MsgBox "Please Select Reason for Skip"
    Me.T_ReasonforSkip.SetFocus
    Exit Sub
    Else

   

End If
End If
End If
End If
DoCmd.GoToRecord , , acNewRec

Exit_cmdAddRecord_Click:
    Exit Sub

Err_cmdAddRecord_Click:
    MsgBox Err.Description
    Resume Exit_cmdAddRecord_Click

End Sub

Private Sub Save_Record_Click()
    If CheckData Then SaveData
End Sub

Private Function CheckData() As Boolean

On Error GoTo CheckData_Error

    CheckData = False
   
    If Nz(Me.T_LockedBy, "") = "" Then
        MsgBox "Please Enter a Name"
        Me.T_LockedBy.SetFocus
        Exit Function
    End If
   
    If Nz(Me.T_LockedLocation, "") = "" Then
        MsgBox "Please Enter Location"
        Me.T_LockedLocation.SetFocus
        Exit Function
    End If
   
    If Nz(Me.T_TypeofSkip, "") = "" Then
        MsgBox "Please Select Type of Skip"
        Me.T_TypeofSkip.SetFocus
        Exit Function
    End If
   
    If Nz(Me.T_ReasonforSkip, "") = "" Then
        MsgBox "Please Select Reason for Skip"
        Me.T_ReasonforSkip.SetFocus
        Exit Function
    End If
   
       
   
   
    CheckData = True
   
Exit_cmdAddRecord_Click:
    Exit Function
   
Err_cmdAddRecord_Click:
    MsgBox Err.Description
    Resume Exit_cmdAddRecord_Click
   
   
    On Error GoTo 0
    Exit Function

CheckData_Error:

    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure CheckData of Documento VBA Form_F_Locked Location Audits"
     
End Function

Private Sub SaveData()

    Dim Rs As Recordset
   
On Error GoTo Savedata_Error

    Set Rs = CurrentDb.OpenRecordset("T_Locked Locations")
   
    Rs.AddNew
    Rs.Fields("Locked By") = Me.T_LockedBy
    Rs.Fields("Location") = Me.T_LockedLocation
    Rs.Fields("Type of Skip") = Me.T_TypeofSkip
    Rs.Fields("Reason for Skip") = Me.T_ReasonforSkip
    Rs.Fields("Input Date") = Now
    Rs.Fields("Comments") = Me.T_LockedLocationComments
   
   
    Rs.Update
   
    Me.T_LockedBy = ""
    Me.T_LockedLocation = ""
    Me.T_TypeofSkip = ""
    Me.T_ReasonforSkip = ""
    Me.T_LockedLocationComments = ""
       
   
    DoCmd.SetWarnings True
   
    On Error GoTo 0
    Exit Sub
   
Savedata_Error:
   
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure SaveData of Document VBA Form_F_Locked Location Audits"
End Sub
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

are you certain that your codes are executed when you click the buttons?
see if click event in the property window have [Event Procedure]

also, make sure that your codes compiles without error
from vba window  Debug > Compile
clear all errors that may arise
Avatar of gsilouisvilleic

ASKER

The [Even Procedure] is under the On Click option.  I went to the compile feature and no errors came up.  I'm really at a loss as to what is causing it to not work when I have very similar code that does.
change this
Dim Rs As Recordset

with
Dim Rs As DAO.Recordset

do a compact and repair, if that don't resolve the problem
upload a copy of the db
Attached is the portion of the database I'm having the issues with.  Thanks for your help with this.
Locked-Locations.accdb
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Worked great, can't believe I missed that.  Thanks for your help! :)