subform increment a value by one for that child record

C

carlee

hello there,

i have problem

my form allows users to enter testing information on a
subject. fields include a date, test name, location and
stick.

each time a user enters a new test, they enter the stick
number the test was performed on. for example, 1,3,4,5

What am i looking for:

i want to have the stick number increment by one for each
time the user clicks "new test". this number may not
always be stick 1 to start. It may be stick 33, and then
next stick would be stick 34, 35,36 etc.

any suggestions on how i can achieve this?

many thanks in advance.

Carlee
 
P

Pavel Romashkin

Make a module-level variable where you store the stick number and
increment it when you need it. Reset it when you need it, too.
If stick number is a field in the table, you can also increment using
DMax + 1 on that field.

Pavel
 
C

carlee

thank you for the advice. would you perhaps be able to
supply some code to fulfil your concept on the table and
resetting the table?

thanks for your patience for a coding newbee.

Cheers,
carlee
 
P

Pavel Romashkin

If you have a table MyTable with a field StickNo that never repeats and
needs to be incremented every time, enter this in Current event of the
form (obviuosly in this case you don't reset StickNo, ever):

IF Me.NewRecord THEN Me!StickNo = DMAX("StickNo", "MyTable") + 1

If you don't have a field or it has repetitive numbers, the user will
have to input the stick no at least once at the beginning of data entry.
When - it is up to you; this is when you reset the counter. The counter
will reset itself if the user opens the form for every new series of
entries, or you can make it reset if the user puts in a new value, or whatever:

in Form_MyForm, in Declarations, put:
Private StickNo as Long

in Current, put

IF Me.NewRecord THEN
StickNo = StickNo + 1
Me.txtStickNo = StickNo
END IF

in AfterUpdate of txtStickNo, put

if Me.txtStickNo <> StickNo THEN StickNo = Me.txtStickNo

Cheers,
Pavel
 

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