form synchronizing on new records

A

ANStech

I have a form which calls another. If I am NOT on a new record, the forms
are in sync.(they open and update to the same record number). However, When
I am on a new record, the original form is set to <autonumber>, then the
second form gets set to <autonumber> and when data is added, the forms are
off by 1.

For instance, I go to the last record on the original form and it is record
11. I then move one record past to record 12. The ID field is set to
<autonumber> but when I click "open next form" the next form is ID =
<autonumber>. when data is added, the number changes to 13. The original
form is then updated on record 13 and nothing happens on record 12.

Can anyone please help
 
K

Ken Snell [MVP]

Sounds as if both forms are bound to the same table (either directly or via
a query). As such, each thinks it is the newest record when you go to a new
record in the form, regardless of which one. You must force the first form
to save the record that you're on (especially if it's a new record) before
you open the second form. You can do this in the code that you're running
when you click the "open next form" button by adding this code step at the
beginning of that code procedure:

If Me.Dirty = True Then Me.Dirty = False
 
J

John Vinson

I have a form which calls another. If I am NOT on a new record, the forms
are in sync.(they open and update to the same record number). However, When
I am on a new record, the original form is set to <autonumber>, then the
second form gets set to <autonumber> and when data is added, the forms are
off by 1.

For instance, I go to the last record on the original form and it is record
11. I then move one record past to record 12. The ID field is set to
<autonumber> but when I click "open next form" the next form is ID =
<autonumber>. when data is added, the number changes to 13. The original
form is then updated on record 13 and nothing happens on record 12.

Can anyone please help

You should ABSOLUTELY NEVER use Autonumbers in two tables to link
those tables. It *will not work*. An Autonumber has one purpose, and
one purpose only - to provide a guaranteed unique link between two
tables. You cannot control the value in an autonumber; if the user
hits Esc in the second form, the current autonumber value will be lost
forever, and the next record will have a *different* autonumber!

It sounds like your second form is based on a Table which you want to
have related to the records in the first form's Table. The correct way
to do this is to include a Long Integer foreign key in the second
table, linked to the autonumber field of the first table. You can
maintain the synchrony between the two tables by using a Subform based
on the second table, on the first form; or you can pass the current
value in VBA code in the OpenForm method. But in any case your second
table should *NOT* rely on its Autonumber as any sort of link to the
first table!

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
Top