autonumber PK scrolling problem

B

bill

hi
i made a form with a subform based on two tables with autonumber primary key
in the second table. My problem is that rolling the scroll mouse on the
subform, the autonumber id incresed like crazy and i cant control the
addition of new records, filling me with null records.
Do i have any chance to stop this ?
 
L

Larry Linson

bill said:
i made a form with a subform based on two tables
with autonumber primary key in the second table. My
problem is that rolling the scroll mouse on the
subform, the autonumber id incresed like crazy and
i cant control the addition of new records, filling me
with null records. Do i have any chance to stop this ?

Seems likely you have some Fields, or Controls, defined with a Default
Value, so the Records being added are not exactly "empty." Is there a Field
which should always exist (not the AutoNumber) in the Record, that has no
Default Value? Make it Required, check for its existence in the
BeforeUpdate event, and set the Cancel argument to True to cancel the
update.

Larry Linson
Microsoft Access MVP
 
B

bill

hi Larry,
yes u have right, i have made a date field with the default value date().
where i can find that cancel argument?and the before update event contains
nothing, is there any code i must write there?
thanks
 
L

Larry Linson

bill said:
hi Larry,
yes u have right, i have made a date field with the default value date().
where i can find that cancel argument?and the before update event contains
nothing, is there any code i must write there?
thanks

Yes, code that you place in the BeforeUpdate event will execute before the
Record is Updated. The Cancel argument is in the (automatically generated)
line that begins the update event:

Private Sub Form_BeforeUpdate(Cancel As Integer)

In design view of the Form, you click the upper leftmost little rectangle on
the Form, if need be to select the Form, right-click to choose Properties,
and in the PropertySheet, click the Events tab. One of the events will be
the BeforeUpdate event. Chose "CodeBuilder".

If you'll tell us the name of a Field that should always be there in a valid
Record, and the name of the Control that is bound to that Field, someone
might suggest code -- it won't be overwhelming.

Larry Linson
Microsoft Access MVP
 
L

Larry Linson

bill said:
the field name and the control name are [arrival date]....

It is a good idea to name or rename the Control to something easy to
distinguish from the name of the Field. You need to choose a Field that will
_always_ be present, but NOT the one that has the default value -- sorry I
did not make that clear.

For purposes of illustration, lets say that Field is Product and the control
in which it would be displayed (or into which it will be entered) is a Text
Box called txtProduct. Code in the BeforeUpdate event would be something
like this:

If IsNull(Me.txtProduct) Then
Cancel = True
Else
... any other code you may want to run here...
End If

or, if there's no other code to run,

If IsNull(Me.txtProduct) Then
Cancel = True
End If

Larry Linson
Microsoft Access MVP
 
B

bill

Thanks you were very helpfull...

Larry Linson said:
bill said:
the field name and the control name are [arrival date]....

It is a good idea to name or rename the Control to something easy to
distinguish from the name of the Field. You need to choose a Field that will
_always_ be present, but NOT the one that has the default value -- sorry I
did not make that clear.

For purposes of illustration, lets say that Field is Product and the control
in which it would be displayed (or into which it will be entered) is a Text
Box called txtProduct. Code in the BeforeUpdate event would be something
like this:

If IsNull(Me.txtProduct) Then
Cancel = True
Else
... any other code you may want to run here...
End If

or, if there's no other code to run,

If IsNull(Me.txtProduct) Then
Cancel = True
End If

Larry Linson
Microsoft Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top