Next Record not working (1 Viewer)

Joye

Registered User.
Local time
Today, 09:02
Joined
Aug 3, 2001
Messages
34
I am working on a form and I have a next button and a previous button as well as a Add new Record button. When they hit next... I have it set up so that it will run a procedure which asks the users if they have made changes to the record, if they say YES, then it opens another form with additional information to fill out. If they say NO, I just want it to go to the next record. It will do this, BUT if there is no NEXT record, and they are already at the last record it is just trying to enter a new record. I need it to have this type of code... but do I try to put this in the procedure or try to direct myself back to the NEXT click code? How do I get it to know when it is an error?

DoCmd.GoToRecord , , acNext

Exit_next_Click:
Exit Sub

Err_next_Click:
MsgBox "You are already at the last record."

THANKS.
 

RichO

Registered Yoozer
Local time
Today, 03:02
Joined
Jan 14, 2004
Messages
1,036
I have a couple ideas for this. First of all, you don't need to ask the user if they changed the form because Access will know this and you can check it using the "dirty" property.

The only way I can think of to count the total number of records in your table to prevent the user from advancing to a new record is with DCount. Is your form based directly on a table or is a query used?

If your form is based on a table you can do something like:

Code:
If Me.CurrentRecord < DCount("*", "MyTable") Then
    DoCmd.GoToRecord, , acNext
Else
    MsgBox "You are at the last record"
End If
 

Joye

Registered User.
Local time
Today, 09:02
Joined
Aug 3, 2001
Messages
34
Dirty property

The only problem with the Dirty property is that it takes effect immediately. I want the users to be able to fill out all the information with the record, name changes, address changes, phone numbers. I'd then like to be able to say... You made changes to the record, please indicate the reason the record was changed... New Address, Moved, Phone Correction....
 

RichO

Registered Yoozer
Local time
Today, 03:02
Joined
Jan 14, 2004
Messages
1,036
OK, I was under the impression that you were relying on the user to let you know if they made a change or not, and asking after every record.

You could always just check the dirty property only when the user attempts to leave the current record or close the form and at that point ask for the reason for the change if applicable.
 

Joye

Registered User.
Local time
Today, 09:02
Joined
Aug 3, 2001
Messages
34
Next Record STILL not working

Well I set up the on dirty property to work on every field which was changed. I cannot figure out how to have it work just when you are ready to exit out of the current record.

My problem is still the NEXT record opening up a new record.

This is how it is set up... I have a form which shows basic information about a property. When they click on the Addresses button it opens a this form I have been talking about - but of course the records are filtered - and will only show addresses for the property the user wants to look at. If they click on NEXT it gives them a Blank Address listing instead of saying YOU ARE ALREADY AT THE LAST ADDRESS. How can Access know there were only TWO filtered records and they should only look at the TWO records.

Thoughts, ideas, suggestions.
 

Mile-O

Back once again...
Local time
Today, 09:02
Joined
Dec 10, 2002
Messages
11,316
Use the form's BeforeUpdate event.
 

Joye

Registered User.
Local time
Today, 09:02
Joined
Aug 3, 2001
Messages
34
?

And what am I suppose to put in that event?
 

Mile-O

Back once again...
Local time
Today, 09:02
Joined
Dec 10, 2002
Messages
11,316
Joye said:
I want the users to be able to fill out all the information with the record, name changes, address changes, phone numbers. I'd then like to be able to say... You made changes to the record, please indicate the reason the record was changed... New Address, Moved, Phone Correction....

Mile-O-Phile said:
Use the form's BeforeUpdate event.

Joye said:
And what am I suppose to put in that event?

Whatever code you put in the Dirty event. :rolleyes:

The BeforeUpdate event is triggered just prior to the saving of a record. In here you can let it run through to completion and save the record or cancel the save.

As for getting to a new record, are you using the default navigation buttons on your form?
 

Joye

Registered User.
Local time
Today, 09:02
Joined
Aug 3, 2001
Messages
34
I am using a Next Button for navigation. The previous button works just fine, tell me I am already at the first record and cannot navigate - but the next button will take you to a blank record every time, instead of telling you that you are already at the last record and there is no next. Unless I say NO to Allow Additions on the form, but I need to allow users to add new records, using the add record button.
 

Joye

Registered User.
Local time
Today, 09:02
Joined
Aug 3, 2001
Messages
34
ALSO - in response to the Before Update idea. I don't understand where to put that code. I can see Before Update on the form properties, and Before Update on the text box properties, but how do you go in and do a Before Update or After Update for the Current Record.
 
R

Rich

Guest
Form_Current
If Me.RecordsetClone.RecordCount=Me.CurrentRecord
Then
Me.CmdNext.Enabled=False
Else
Me.CmdNext.Enabled=True
End If
End Sub
 

Users who are viewing this thread

Top Bottom