gsilouisvilleic
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_Aud it_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.SetFoc us
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.SetFocu s
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.SetFoc us
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.SetFocu s
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_LockedLocationComment s
Rs.Update
Me.T_LockedBy = ""
Me.T_LockedLocation = ""
Me.T_TypeofSkip = ""
Me.T_ReasonforSkip = ""
Me.T_LockedLocationComment s = ""
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
Thanks,
Cassie
Private Sub B_Save_Locked_Location_Aud
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.SetFoc
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.SetFocu
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.SetFoc
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.SetFocu
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
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_LockedLocationComment
Rs.Update
Me.T_LockedBy = ""
Me.T_LockedLocation = ""
Me.T_TypeofSkip = ""
Me.T_ReasonforSkip = ""
Me.T_LockedLocationComment
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
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
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
ASKER
Attached is the portion of the database I'm having the issues with. Thanks for your help with this.
Locked-Locations.accdb
Locked-Locations.accdb
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Worked great, can't believe I missed that. Thanks for your help! :)
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