Run-time Error '-2147352567 (80020009)' When I Select 1st Record In Subform, Access 2

skoolz

Registered User.
Local time
Today, 04:19
Joined
Jun 26, 2015
Messages
32
Hi Experts...

Another help call and I must admit that I am impressed that 7 out of my 8 help posts have been solved by the contributors and Mods here so Kudos!!

I have this code that has outbugged me... 1 full day messing with it so if I can't solve this then my project ends!
Issue - I have 2 subforms called R_P_Data_P_Sub and R_P_Data_P_Subfrm. They are table views of a table R_P_Data_P. R_P_Data_P_Sub is on tab one of main control form and R_P_Data_P_Subfrm is on tab 2. My function buttons are on tab 2 and from there I can select records and delete or edit them as long as I select the 2nd record onwards. If I select the first record I get the above error which is captured by the error handler2 below but despite my requery and setfocus lines it does not solve the problem and I cannot delete the record and keep looping in the error handling loop. However, if the subform view have 2 or more records and I select the record 2 and then select record 1 again I can edit or delete and the code executes. Now this far from ideal work around is ok if the subform contains 2 records but if I only have one record in the subform with no other records to select I'm stuck in the error loop.

Code:
Private Sub Delete_A_Click()
    
On Error GoTo ErrorHandler2

    'Delete record code
    'check existing selected record
    If Not (Me.R_P_Data_P_Subfrm.Form.Recordset.EOF And Me.R_P_Data_P_Subfrm.Form.Recordset.BOF) Then
       'Confirm Delete
       If MsgBox("Are you sure you want to Delete the selected record?", vbYesNo) = vbYes Then
            'Execute Deletion           
            CurrentDb.Execute "DELETE FROM R_P_Data_P " & _
                      " WHERE rID=" & Me.R_P_Data_P_Subfrm.Form.Recordset.Fields("rID")

            'Refresh data in subform list
             R_P_Data_P_sub.Form.Requery
             R_P_Data_P_Subfrm.Form.Requery
             MsgBox ("Record Deleted!")
       End If
    End If


Exit Sub

ErrorHandler2:
 MsgBox "Invalid record selection, please try selecting your record again", , "Record Selection Error"
 'Refresh data in subform list

Me.Controls("R_P_Data_P_Subfrm").Form.Requery
' Sets focus to 1st record.
Me.R_P_Data_P_Subfrm.SetFocus 
RunCommand acCmdSelectRecord

End Sub
Please Please help because this is a potential show stopper for me!!!

Thanks in advance
 
Before I even look at any code, can you first tell us what the error message is? Not just the error code.
 
Do you need all that code, can't you just test if Me.R_P_Data_P_Subfrm.Form.Recordset.Fields("rID") isn't null?
 

Users who are viewing this thread

Back
Top Bottom