Incremental Number DMAX (

R

RamonHiram

I am totally new into programming (even in access). I am trying to create a
custom auto number field where I need to look up the highest value of an item
that belongs to a certain field within the same table.
The DMAX works if I use it as a principal form. However, since both fields
belongs to a subform, the DMAX doesn't works properly.

tbl: Series
fields: [InitialSerie] and [FinalSerie] (every record has an InitialSerie and
a FinalSerie).
I am trying to make that the next record's [InitialSerie] is the last
record's [FinalSerie] +1. At the same time, in same record, the [FinalSerie]
is the [InitialSerie] + 30 (this last part is already set).
These fields are contained in the SUBFRM-Series, that is within FRM-Orden.
I'll appreciate much your help.
Thanks in advance.
 
B

BruceM

If FinalSerie is always 30 after the initial series there is no need to
store the value. Rather than using FinalSerie + 1, then InitialSerie + 30,
just use InitialSerie + 31.
When code does not work as intended it is best to post the code. Show the
code when you are using DMax on the main form, and explain how you are
running the code (a command button, the current event, a query, a text box
control source?). Then explain what happens when you run the code from the
subform, including the result you expect and the actual result. Any
explanation will need to include a description of how the main form table
and subform table are related.
 
R

RamonHiram via AccessMonster.com

Hello Bruce:
Thank you very much for your advice. First of all, I hope you forgive my
inexperience in my vocabulary and the way I expose my problem. As you can see
I am an amateur in programing and this is my first time.

Yet I can't say that I have a code because I am using the default value at
the properties window in the access design view (not in the MS VisualBasic
CODE). I hope you might help me with a code whether it is needed to solve my
situation.

I have two fields in a table and presented as a subform. These fields
maintain a series sequence for every record. Lets say [fieldA] and [fieldB]
are my fields. In the first record, the series is 1-30 ( [fieldA] being 1 and
[fieldB] being 30 ); in the second record, the series is 31-60 ( [fieldA]
is 31 and [fieldB] is 60 ); and so on…

In every record of the table (TBL-Series), it is required that [fieldA]
establishes the first number of the series and [fieldB] establish the last
number of the series. In the next record is needed that [fieldA] be [fieldB]
+1 of the last record (besides, within the record, I automated that [fieldB]
be [fieldA] +30 after [fieldA]’s update, and so far it works properly).

This subform is contained in a mother form. Neither of these fields are
linked directly to the mother form, nor are PK.

I tried the DMAX as default value for the [fieldA]= DMAX("FieldB","TBL-
Series")+1 . However it is not working.
What can I do to make this happen.

Once again, thank you very much for your attention.
If FinalSerie is always 30 after the initial series there is no need to
store the value. Rather than using FinalSerie + 1, then InitialSerie + 30,
just use InitialSerie + 31.
When code does not work as intended it is best to post the code. Show the
code when you are using DMax on the main form, and explain how you are
running the code (a command button, the current event, a query, a text box
control source?). Then explain what happens when you run the code from the
subform, including the result you expect and the actual result. Any
explanation will need to include a description of how the main form table
and subform table are related.
I am totally new into programming (even in access). I am trying to create a
custom auto number field where I need to look up the highest value of an
[quoted text clipped - 14 lines]
I'll appreciate much your help.
Thanks in advance.
 
B

BruceM

Responses inline.

RamonHiram via AccessMonster.com said:
Hello Bruce:
Thank you very much for your advice. First of all, I hope you forgive my
inexperience in my vocabulary and the way I expose my problem. As you can
see
I am an amateur in programing and this is my first time.

Yet I can't say that I have a code because I am using the default value at
the properties window in the access design view (not in the MS VisualBasic
CODE). I hope you might help me with a code whether it is needed to solve
my
situation.

Do you mean the table design view? If so, I don't think you can use DMax in
the Default Value expression. Help is remarkable unhelpful on this point,
so I can't say for sure, but I think you need to use DMax as the default
value of a control bound to the field, or else use VBA.
I have two fields in a table and presented as a subform. These fields
maintain a series sequence for every record. Lets say [fieldA] and
[fieldB]
are my fields. In the first record, the series is 1-30 ( [fieldA] being 1
and
[fieldB] being 30 ); in the second record, the series is 31-60 (
[fieldA]
is 31 and [fieldB] is 60 ); and so on…

In every record of the table (TBL-Series), it is required that [fieldA]
establishes the first number of the series and [fieldB] establish the last
number of the series. In the next record is needed that [fieldA] be
[fieldB]
+1 of the last record (besides, within the record, I automated that
[fieldB]
be [fieldA] +30 after [fieldA]’s update, and so far it works properly).

There is no requirement that fieldB be set to anything, or that it exist at
all. Rather, there is a requirement that you know the date 30 days after
the date in fieldA. For that you can use the DateAdd function as the
Control Source of a text box:
=DateAdd("d",30,[fieldA])

By the way, if you are looking to add a month, you can use "m" for "month"
instead of 30 days. Help does have useful information about DateAdd.
This subform is contained in a mother form. Neither of these fields are
linked directly to the mother form, nor are PK.

I tried the DMAX as default value for the [fieldA]= DMAX("FieldB","TBL-
Series")+1 . However it is not working.
What can I do to make this happen.

Back to what I said before about not storing FieldB:
=DMax("FieldA","TBL_Series") + 31
If FieldA is a DateTime field it should work to add 31 days in this way, but
remember that DateAdd or DateDiff can be used for finer control.

"It is not working" is not enough information. Where exactly are you using
the expression? In what way does it not work -- incorrect number, no
number, or what?
Once again, thank you very much for your attention.
If FinalSerie is always 30 after the initial series there is no need to
store the value. Rather than using FinalSerie + 1, then InitialSerie +
30,
just use InitialSerie + 31.
When code does not work as intended it is best to post the code. Show the
code when you are using DMax on the main form, and explain how you are
running the code (a command button, the current event, a query, a text box
control source?). Then explain what happens when you run the code from
the
subform, including the result you expect and the actual result. Any
explanation will need to include a description of how the main form table
and subform table are related.
I am totally new into programming (even in access). I am trying to create
a
custom auto number field where I need to look up the highest value of an
[quoted text clipped - 14 lines]
I'll appreciate much your help.
Thanks in advance.
 

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