Solved No current record error (1 Viewer)

oxicottin

Learning by pecking away....
Local time
Today, 08:02
Joined
Jun 26, 2007
Messages
856
Hello, I have a button that clears my "Who Logged In" table, and the button works and it requerys the form BUT when I close the form, I get an error message. Why am I getting the message?

Code:
Private Sub cmdDeleteAllRecords_Click()

    CurrentDb.Execute "Delete * From tbl_WhoLoggedIn"
  
    DoCmd.Requery
  
End Sub

I can supress the error message but I would like to know why im getting it...

Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
    If DataErr = 3021 Then Response = 0
End Sub
 

Attachments

  • Capture.JPG
    Capture.JPG
    14 KB · Views: 36
Last edited:

Solo712

Registered User.
Local time
Today, 08:02
Joined
Oct 19, 2012
Messages
828
Instead of requerying an empty table you should set the form for a new record:

Code:
DoCmd.GoToRecord , , acNewRec

Best,
Jiri
 

oxicottin

Learning by pecking away....
Local time
Today, 08:02
Joined
Jun 26, 2007
Messages
856
Instead of requerying an empty table you should set the form for a new record:

Code:
DoCmd.GoToRecord , , acNewRec

Best,
Jiri

It gives me an error 2105 can't go to specified record. I'm just going to use the error handling. Thanks!
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:02
Joined
Sep 21, 2011
Messages
14,311
Unlikely the code that you show is the problem then?, if it happens when you close the form?
What code runs when you close the form?

Have you even walked through your code? :(
 

oxicottin

Learning by pecking away....
Local time
Today, 08:02
Joined
Jun 26, 2007
Messages
856
@Gasman acually there isnt really anything on this form other than its so I can view logIn and logout times/names and I clear the table after I view them. Below is everything I have behind form.

Code:
Option Compare Database
Option Explicit

Private Sub cmdDeleteAllRecords_Click()
 
    CurrentDb.Execute "Delete * From tbl_WhoLoggedIn"
    
    DoCmd.Requery
    
End Sub

Private Sub Form_Current()
    On Error GoTo Form_Current_Err
    
'Counts records that were found
    Me.txtTotalRecords.Value = Me.Recordset.RecordCount
    
Form_Current_Exit:
    Exit Sub
Form_Current_Err:
    MsgBox Err.Description & " in Form_Current"
    Resume Form_Current_Exit
End Sub

Private Sub Form_Unload(Cancel As Integer)
    
    If CurrentProject.AllForms("frm_Switchboard").IsLoaded Then
        Forms![frm_Switchboard].Visible = True
    End If
    
End Sub

Private Sub Form_Error(DataErr As Integer, Response As Integer)
    If DataErr = 3021 Then Response = 0
End Sub
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:02
Joined
Feb 19, 2002
Messages
43,293
Using an action query to update records bound to a form is always problematic. I'm guessing that it is the code in the current event that is triggering the error message.
 

Users who are viewing this thread

Top Bottom