no current record on close

suepowell

Registered User.
Local time
Today, 23:51
Joined
Mar 25, 2003
Messages
282
Hi,

I have a very large and complicated form with several sub forms which does what I want mostly.

If I close it with a button I have put on there which runs the docmd.close action it's fine. However if I close the form using the cross top right I get the message "no current record". Once you have clicked yes the form closes, but this is obviously not ideal. I could of course disable the button, but does anyone know where I could look to find the problem.

The message pops up before the unload or close method is fired on the main form or any of the subforms, I can't seem to break the code before the message appears to step through it and find the error.

Any pointers would be gratefully received.

Sue
 
I am not exactly sure how to deal with the problem by correcting whatever error there is or that the computer thinks is there.

Howver, here is some code that will help tell you the error number and some code to change the error message to whatever you want (including absolutely nothing).

Hope this helps at least until you figure out the underlying cause.

This code allows you to check what the error # is so you can create your own error message with the code immediately after this
Private Sub Form_Error(DataErr As Integer, Response As Integer)
MsgBox "Error#: " & DataErr ' Display the error number
Response = acDataErrDisplay ' Display Default message
End Sub


Private Sub Form_Error(DataErr As Integer, Response As Integer) 'Overrides default error for input mask violations and replaces it with a more descriptive messagebox
Const INPUTMASK_VIOLATION = 2279 'this is the error number. Change this to what you get from the other code. Make sure not to have both sets of code in the program at once because that will cause an error
If DataErr = INPUTMASK_VIOLATION Then
MsgBox "There was an input mask violation! The UserID must be 4 letters followed by 2 numbers. The dates must be mm/dd/yyyy."
Response = acDataErrContinue
End If
End Sub
 
you must have some code running to do this

maybe a default value somewhere

sometimes hard to trace things like this though
 
If you find you can't find it, you might post the database and we can try to find it.
 
re-reading it, it may well be something in a (current?) event on one of the subforms causing this.
 
I wouldn't thik it was anything in the Form_Currrent event, as there is a current record at that point in time. As Bob has suggested, you really need to attach your database file so we can look at it because there's simply so many possibilities due to the multiple subforms.

There is, in fact, no current record by the time Form_Unload and Form_Close fires, whether on the main form or one of the subforms, and the error would seem to indicate that you have code trying to do something to a current record at one of these points.

Zio it and post it!
 
Thanks for all your replies,

I have used Voltron's suggestion and, with the addition of each subform name into the error messages I have narrowed it down to the subform causing the problem, which gives me a much better chance of finding the answer.

I can't upload the database, it is much too big and complicated, but with the suggestions I have had here I'm sure I will find it soon.

I'll post the answer if I find one so it helps others.

That code from Voltron is going to be really useful when I can't find the right place in my code to break and step though.

Thanks again everyone.
 
Just a long shot and wild guess but assuming that by clicking the button on your form your either keeping the focus on the form or forcing an automatic save as a long shot try something like
Private Sub Form_Unload(Cancel As Integer)
Screen.PreviousControl.Requery
End Sub
 

Users who are viewing this thread

Back
Top Bottom