Sequential number autofill

  • Thread starter Jeff S via AccessMonster.com
  • Start date
J

Jeff S via AccessMonster.com

I have a subform (worksheet format) in my main form. This subform is used to
capture events related to pallet numbers. On my subform, there is a pallet#
field. The number of the pallet is usually sequential and there is a lot of
them to enter. This task was previously performed in excel by dragging the
corner of the cell which would increase the value of the pallet# by 1 on each
cell
I would want access to be able to do the same in my subform worksheet but
cannot figure how
I need to have total flexibility to enter any pallet number that I want in my
pallet# field, but if I have a sequence of 10 pallet numbers, I need a way to
automate the entry.
I was thinking to be able to add 1 to the previous pallet# on my subform
everytime I dble clic on it but I cannot figure out how to do that
 
W

Wayne Morgan

Would each pallet be entered as a new record? If so, set the default value
of the pallet number to one more than the one currently entered each time
you save a new record. Since the default value is being set by code, it will
not be there when the form is first opened, it will only exist after you
enter the first record for that session.

In the form's BeforeUpdate event:
If Me.NewRecord Then
Me.txtPalletNumber.DefaultValue = Me.txtPalletNumber + 1
End If

The BeforeUpdate event will happen before the form moves to the next new
record. When you get to the next new record, the DefaultValue property will
automatically fill in the textbox for you. However, the DefaultValue
property will NOT make the record "dirty", so the record won't be saved
unless you make a change yourself to at least one field.
 
G

Guest

Jeff S via AccessMonster.com said:
I was thinking to be able to add 1 to the previous pallet# on my subform
everytime I dble clic on it but I cannot figure out how to do that

Add a handler on the form's double-click method. Select max(pallet#) from
the list. Add one, and use it in a new record.

If the records are in the database, which I assume they are, simply modify
your form's datasource sql to get the number. If the form uses something
like...

select * from tblTheStuff where ...

then you'd use...

select max(palletnum) from tblTheStuff where ...

Maury
 
J

Jeff S via AccessMonster.com

Thanks for the help Wayne.
I actually just found a solution to my problem which is similar to yours:
On the dble clic property of my pallet# field I input the following code:

Private Sub Pallet__DblClick(Cancel As Integer)
DoCmd.GoToRecord , , acNewRec
[Pallet#] = DMax("[Pallet#]", "TB_Hold Details") + 1
End Sub

Where TB_Hold Details is the table that store the info of my subform
It allows me to add 1 to the highest pallet number store in the database

Thanks again



Wayne said:
Would each pallet be entered as a new record? If so, set the default value
of the pallet number to one more than the one currently entered each time
you save a new record. Since the default value is being set by code, it will
not be there when the form is first opened, it will only exist after you
enter the first record for that session.

In the form's BeforeUpdate event:
If Me.NewRecord Then
Me.txtPalletNumber.DefaultValue = Me.txtPalletNumber + 1
End If

The BeforeUpdate event will happen before the form moves to the next new
record. When you get to the next new record, the DefaultValue property will
automatically fill in the textbox for you. However, the DefaultValue
property will NOT make the record "dirty", so the record won't be saved
unless you make a change yourself to at least one field.
I have a subform (worksheet format) in my main form. This subform is used
to
[quoted text clipped - 15 lines]
I was thinking to be able to add 1 to the previous pallet# on my subform
everytime I dble clic on it but I cannot figure out how to do that
 
W

Wayne Morgan

I thought about that also, but if pallets come arrive in sequential lots,
that's one thing, but are the lots sequential? In other words, will the
pallets you receive tomorrow continue the sequential numbering from today's
lot?
 

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