View Full Version : Error Msg: 'No Current Record'


Little_Man22
10-03-2001, 02:33 PM
Hi,

I have a database that when opened, a form called Client automatically is maximized on the user's screen. However, when you go to exit this form (click on the x in the top right corner) you get the error message 'No Current Record'. It doesn't matter how long you've been on this form, if you've made any changes, or even saved anything, you still get the error message without fail...

Any ideas?

btw I've also posted this message under the general section of the forum but I'm hoping that you guys will be a little more specialized with regards to forms http://www.access-programmers.co.uk/ubb/smile.gif

Thanks in advance,
Ryan.

Jack Cowley
10-03-2001, 04:21 PM
What happens if you add a command button that closes the form? Do you still get the same error? I have not seen what you describe before so my inclination is to suggest a slightly corrupted form. Try making a new one and see if you get the same message....

Little_Man22
10-03-2001, 04:45 PM
Hey Jack,

The event procedure for 'on close' is as follows (this is probably where the error is occuring):

Private Sub Form_Close()
'UpdateRecentSearches
If Not IsUser("Management") Then
Application.Quit acQuitSaveAll
End If

End Sub

I'm considered 'Management' and am the only one who experiences this error. Also, it only happens the first time you go to close the form. After this any subsequent 'closings' work fine...

Any ideas?

Little_Man22
10-03-2001, 04:56 PM
Hey again,

I tired doing the form over but still get the same message:

No current record. (Error 3021)

This error occurs after the unsuccessful application of one of the Find methods or the Seek method, when the underlying Recordset contains no records or the record has been deleted. Move to or select another record, and try the operation again. If the Recordset is empty, you cannot position to a current record. Check the BOF and EOF properties. (pasted from help file)

I actually don't get the message only when I first open the program either...it occurs each time I close a record for the first time during that particular session.

I'd appreciate any adivce that anyone may have.

Thanks,
Ryan.

jwindon
10-03-2001, 05:05 PM
I don't see a ELSE part of that block. What about Cancel=True.

Also, I'm not familiar with the Application.Quit, but I think I see that there may be a problem with quitting BEFORE the SAVE ALL. If you have executed a quit, there is nothing to save...ergo...NO RECORD

[This message has been edited by jwindon (edited 10-03-2001).]

Jack Cowley
10-03-2001, 05:40 PM
Ryan -

I do not recognize the IsUser function. Is this a function that you created? I assume this has to do with who is logged into the database....

Your code says that if Managment is NOT the user then quit Access. Since you are Management then the quit code should be skipped so I am wondering why it is closing. Have you put a 'watch' into you code and stepped through it to see what bits of your code are being executed? Also in your search code you should have some code to cancel the code if the search comes up empty. i.e. If rs.recordcount <= 0 Then Exit Sub.

The old brain closely resembles porridge tonight so I may be out in left field on this one...

Little_Man22
10-03-2001, 05:51 PM
jwindon: you might be onto something...what should the code look like if I followed your train of thought.

Jack: it's weird because I only get the error message when I close the form while certain records are showing. In other words the form may close fine if record A is on the screen, but if record B is showing then I will get the error message.

Pat Hartman
10-03-2001, 05:55 PM
There are two quit methods.
Old code which is still supported for compatibility
DoCmd.Quit acQuitSaveAll
And New code - preferred.
Application.Quit acSaveYes

As it happens both intrinsic constants have the same value so using the wrong one as you have shouldn't cause a problem. However, according to help, the save option for this method refers to database objects NOT records. Is that what you though was being saved? I think you will find that the BeforeUpdate event of any dirty form will actually execute prior to the Close event so any unsaved record would already have been saved by the time this code runs.

Look at the IsUser() function. What is it doing?

jwindon
10-03-2001, 05:59 PM
I'll give it a shot:


Private Sub Form_Close()

'UpdateRecentSearches
'I am assuming IsUser is a control name
If Not IsUser ="Management" Then

DoCmd.RunCommand acCmdSave
DoCmd.Quit acQuitSaveAll

Else

'Replace your next action here
End If
End Sub


[This message has been edited by jwindon (edited 10-03-2001).]

Little_Man22
10-03-2001, 06:53 PM
I just thought that you guys should know that I only get this error message for half of the records. In other words, if I attempt to close the form when Record A is visible I won't recieve any error messages, however, if I attempt to close the form where Record B is showing I get the message.

Here's the function IsUser:

Function IsUser(strGroup As String) As Boolean
' Purpose: Determines if the current user belongs to the specified
' group.
' Accepts: The name of a group.
' Returns: True if the current user is a member of the specified
' group, False if the current user is not a member of
' the group.
' Assumes: The existence of a user called Developer in the Admins
' group, with no password.
'************************************************* ***************

On Error GoTo err_CurrentUserInGroup

Dim MyWorkSpace As Workspace
Dim MyGroup As Group, usUser As User

' Create a new workspace as a member of the Admins group.
Set MyWorkSpace = DBEngine.CreateWorkspace("SPECIAL", "Testadmin", "")

Set MyGroup = MyWorkSpace.Groups(strGroup)
For Each usUser In MyGroup.Users
If usUser.Name = CurrentUser Then
IsUser = True
End If
Next usUser

MyWorkSpace.Close
Exit Function

err_CurrentUserInGroup:
MsgBox Error(Err)

Exit Function

End Function

Also it might be worth noting that the data tab for the form contains the following:
Record Source: Client
Filter By: ((Client.BusCity="oakville"))
...and then just the regular yes' and no's.

Ryan.

Little_Man22
10-03-2001, 06:57 PM
Here's the help file that comes up with the error message:

No current record. (Error 3021)
This error occurs after the unsuccessful application of one of the Find methods or the Seek method, when the underlying Recordset contains no records or the record has been deleted. Move to or select another record, and try the operation again. If the Recordset is empty, you cannot position to a current record. Check the BOF and EOF properties.

Little_Man22
10-03-2001, 07:25 PM
ACTUALLY...it has nothing to do with the onclose event procedure...I just deleted the entire code and tried to close the form (without any procedure) and I still got the error message...

Any ideas what else it could be?

charityg
10-04-2001, 08:57 AM
Have you inserted a breakpoint in the code to pinpoint the exact line of code or function that is causing the error?

Little_Man22
10-04-2001, 09:18 AM
I figured out what the problem is but don't know how to fix it.

I have a main form containing 5 tabs. One of these tabs is labelled 'Notes' and whenever the current client, who is showing on the form, has nothing entered under this tab I get the error message if I close the form while s/he is being displayed. However, if a client is being displayed who has stuff entered under the 'Notes' tab then when I close the form I do not get the error message.

Weird eh? But it's even weirder. If I simply tab through the records using the record selectors and come to a record with no info under the 'Notes' tab and try to close the form then I get the error message. However, if I do a search and bring up this same record and close the form I don't get any message...

I don't really understand this...Can you help think of any type of solution to this problem?

Ryan.

Little_Man22
10-04-2001, 10:27 AM
The answer has something to do with the oncurrent event procedure of the notes tab:

Private Sub Form_Current()
On Error GoTo ErrChk

If Me.Recordset.RecordCount > 10 Then
Me.ScrollBars = 2
Else
Me.ScrollBars = 0
End If


Exit Sub
ErrChk:
If Err.Number <> 2452 And Not Err.Number = 3021 Then
MsgBox Err.Number & Err.Description
End If

End Sub

The error message 'No Current Record' is Err.Number 3021 so how can I change this code so that I don't get an error when I close the form when the client has nothing entered into this tab?

Jack Cowley
10-04-2001, 04:36 PM
ErrChk:
If Err.Number = 3021 then Exit Sub
MsgBox Err.Number & Err.Description

If the error happens then no message and the subroutine is exited. Boy, do I hope I have it right this time!

Little_Man22
10-04-2001, 06:04 PM
That worked perfectly Jack...thanks a lot http://www.access-programmers.co.uk/ubb/smile.gif