
Signature
Steve Schapel, Microsoft Access MVP
Alex and Steve,
Thank you for the replies! Ok, I tried combining both of your
suggestions, and now get the error:
Run-time error '2046':
The command or action "DeleteRecord" isn't available now.
Which would tell me that the record isn't being saved yet. Which will
be possible if the user hasn't tabbed into the subform yet, but I tried
it with going into the subform and I still get the error. Another
thing, in this code, aren't I saying to delete the subform's record?
I'm still learning how to use recordsets so, please, be patient.
Thanks!
Here's my new code:
Private Sub Form_Unload(Cancel As Integer)
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set dbs = CurrentDb
Set rst = Forms!zquotemain1!DetailsSub.Form.RecordsetClone
If rst.RecordCount = 0 Then
'DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
'DoCmd.SetWarnings True
End If
End Sub
Alex White MCDBA MCSE - 09 May 2005 07:25 GMT
Hi Angi,
this should help
change your code to the following
Private Sub Form_Unload(Cancel As Integer)
on error goto Err_Form_Unload
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set dbs = CurrentDb
Set rst = Forms!zquotemain1!DetailsSub.Form.RecordsetClone
If rst.RecordCount = 0 Then
'DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
'DoCmd.SetWarnings True
End If
Exit_Form_Unload:
exit sub
Err_Form_Unload:
if err.number <> 2046 then
msgbox err.number & " " & err.description
end if
resume next
End Sub
this allows your code to silently trap the error and ignore it, should do
the job.

Signature
Regards
Alex White MCDBA MCSE
http://www.intralan.co.uk
> Alex and Steve,
> Thank you for the replies! Ok, I tried combining both of your
[quoted text clipped - 26 lines]
>
> End Sub
Steve Schapel - 09 May 2005 10:49 GMT
Angi,
Have you put this code on the Unload event of the subform? I meant the
main form.
Another minor point... I would do it like this:
Set rst = Me.DetailsSub.Form.RecordsetClone

Signature
Steve Schapel, Microsoft Access MVP
> Alex and Steve,
> Thank you for the replies! Ok, I tried combining both of your
[quoted text clipped - 26 lines]
>
> End Sub
Angi - 09 May 2005 15:18 GMT
Steve,
Ok, did what you said and it does ignore the 2046, but now I'm getting
an error
3021 No current record
I tried ignoring that one too, but it's not working. Now what?
Angi - 09 May 2005 15:21 GMT
Sorry about that, I meant Alex.
Steve,
Yes it is in the Unload event of the main form....not the subform. I
changed it to the me. I did that before and it didn't like
it...must've been some other error going on at the time. Thanks for
that!
Angi - 10 May 2005 23:31 GMT
Anyone have any ideas on how to now get rid of the 3021 error?
I have:
Exit_Form_Unload:
Exit Sub
Err_Form_Unload:
If Err.Number <> 2046 Or Err.Number <> 3021 Then
MsgBox Err.Number & " " & Err.Description
End If
Resume Next
Douglas J. Steele - 11 May 2005 01:29 GMT
If Err.Number <> 2046 And Err.Number <> 3021 Then
The way you have it, if Err.Number is 3021, then the first part of the
comparison (Err.Number <> 2046) is obviously True.

Signature
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
> Anyone have any ideas on how to now get rid of the 3021 error?
>
[quoted text clipped - 6 lines]
> End If
> Resume Next
Alex White MCDBA MCSE - 11 May 2005 06:04 GMT
Angi,
To follow Doug,
You Need
either
if err.number = 2046 then
resume next ' or whatever you want to do
elseif err.number = 3021 then
resume next ' or whatever you want to do
endif
or the select case
select case err.number
case 2046
resume next
case 3021
resume next
case else
end select

Signature
Regards
Alex White MCDBA MCSE
http://www.intralan.co.uk
> If Err.Number <> 2046 And Err.Number <> 3021 Then
>
[quoted text clipped - 11 lines]
>> End If
>> Resume Next