Another numbering system question

A

AusTexRich

I want to create a numbering system, in a three character format, in a form
starting at "001" and so on. Now, because the of the formatting of the prior
data from an Excel file, I've had to distinguish one year's records from the
next with a text field "08" (year). So when a new record is added, the text
"08" is added and then the count begins at "001". How do I do that?

table fields are: [I_period] - "08", [row_num] - "001", "002, etc,.
Thanks all.
 
M

mscertified

What is the purpose of this numbering? If is going to become the primary key
of a table, then you are doing it all wrong. Dont try to embed data (the
year) in a key.
As far as assigning the numbers you will need to set up a table with a
unique primary key. To assign a number INSERT the row in the table with the
next key. This method assures a unique number; it does not however assure
there wont be missing numbers in the sequence.

-Dorian
 
A

AusTexRich

Hi,
The "08" is supposed to help distinguish prior years' records. The
numbering, "001", "002" etc, was for each row added (for each year). Each
prior year's activity had a distinctive row number "001", "002" etc.

The data lived in an Excel file and didn't have any validations. I had a
lot of clean up.

So I thought I'd continue the madness by entering the "08" at the start of
the new year for each new record and begin my numbering "001", "002" etc.

--
AusTexRich


mscertified said:
What is the purpose of this numbering? If is going to become the primary key
of a table, then you are doing it all wrong. Dont try to embed data (the
year) in a key.
As far as assigning the numbers you will need to set up a table with a
unique primary key. To assign a number INSERT the row in the table with the
next key. This method assures a unique number; it does not however assure
there wont be missing numbers in the sequence.

-Dorian


AusTexRich said:
I want to create a numbering system, in a three character format, in a form
starting at "001" and so on. Now, because the of the formatting of the prior
data from an Excel file, I've had to distinguish one year's records from the
next with a text field "08" (year). So when a new record is added, the text
"08" is added and then the count begins at "001". How do I do that?

table fields are: [I_period] - "08", [row_num] - "001", "002, etc,.
Thanks all.
 
B

BruceM

Assuming the year is stored somewhere in the record (as part of a date
field), you could do something like this in the After Update event for the
control bound to the date field:
If Me.NewRecord Then
Me.NumberField = Nz(DMax("NumberField", "YourTable", _
"Year([DateField]) = " & Year([DateField])), 0) + 1
End If

Use your own field and table names, of course.

To display the number, you could do something like this as the Control
Source of an unbound text box:
=Format([DateField],"yy") & "-" & Format([NumberField],"000")

Keep in mind that NumberField cannot be used as the primary key, since it
will start over from 0 each year. If you already have a primary key that is
not a problem. If this number is to be the primary key you could add the
year to the beginning of the number, but that involves a few more steps, so
I will wait until I hear more about the details. Some would argue that
adding the year to the number is storing the year redundantly, but without
that you would need either a compound primary key or a separate primary key
field.

The general point here is that you can build an automatically incrementing
number into your database. As always, the details dictate the specifics.
 
A

AusTexRich

Hi,
Great stuff. I very appreciative of your help. You guys always have some
great stuff.
My problem is adding new records to a table of preexisting data that is
grouped by year (kind of) and each prior year has its own count beginning at
001 to the last record for the year.
If I use DMax I get the next record 539. Great for this year, but, what
about next year? I'd like the "counter" to reset to "001".

I was hoping that if I add a text field to capture the year "08" I can base
a numbering system on that and start at "001".
--
AusTexRich


BruceM said:
Assuming the year is stored somewhere in the record (as part of a date
field), you could do something like this in the After Update event for the
control bound to the date field:
If Me.NewRecord Then
Me.NumberField = Nz(DMax("NumberField", "YourTable", _
"Year([DateField]) = " & Year([DateField])), 0) + 1
End If

Use your own field and table names, of course.

To display the number, you could do something like this as the Control
Source of an unbound text box:
=Format([DateField],"yy") & "-" & Format([NumberField],"000")

Keep in mind that NumberField cannot be used as the primary key, since it
will start over from 0 each year. If you already have a primary key that is
not a problem. If this number is to be the primary key you could add the
year to the beginning of the number, but that involves a few more steps, so
I will wait until I hear more about the details. Some would argue that
adding the year to the number is storing the year redundantly, but without
that you would need either a compound primary key or a separate primary key
field.

The general point here is that you can build an automatically incrementing
number into your database. As always, the details dictate the specifics.

AusTexRich said:
I want to create a numbering system, in a three character format, in a form
starting at "001" and so on. Now, because the of the formatting of the
prior
data from an Excel file, I've had to distinguish one year's records from
the
next with a text field "08" (year). So when a new record is added, the
text
"08" is added and then the count begins at "001". How do I do that?

table fields are: [I_period] - "08", [row_num] - "001", "002, etc,.
Thanks all.
 
B

BruceM

It will start over at 1 next year. Note this part of the code for DMax,
which is the optional criteria:
"Year([DateField]) = " & Year([DateField])
If the DMax statement just included the following:
DMax("NumberField", "YourTable") + 1
then Access would find the largest value for NumberField in YourTable and
add 1 to it.
However, with the optional criteria added:
DMax("NumberField", "YourTable","Year([DateField]) = " & Year([DateField]) +
1
Access will find the largest value for NumberField in YourTable for which
the Year portion of DateField is the same as the Year portion of DateField
for the current record, and add 1 to it.
The Nz in the original code allows for the fact that for the year's first
record there will be no records in which Year from DateField equals Year
from the current record. In that case DMax will produce a null value. Nz
replaces the null with a 0, to which 1 is added, resulting in a value of 1
in NumberField for the first record of any year.
Do you have a date field in the record?
Is there a primary key field or combination of fields?
My original post includes the reasons why I ask these questions. The year
can be added to the number and stored, but first I'm trying to find out if
it's necessary. If it isn't you can just concatenate the two-digit year
with the number as I described.

AusTexRich said:
Hi,
Great stuff. I very appreciative of your help. You guys always have some
great stuff.
My problem is adding new records to a table of preexisting data that is
grouped by year (kind of) and each prior year has its own count beginning
at
001 to the last record for the year.
If I use DMax I get the next record 539. Great for this year, but, what
about next year? I'd like the "counter" to reset to "001".

I was hoping that if I add a text field to capture the year "08" I can
base
a numbering system on that and start at "001".
--
AusTexRich


BruceM said:
Assuming the year is stored somewhere in the record (as part of a date
field), you could do something like this in the After Update event for
the
control bound to the date field:
If Me.NewRecord Then
Me.NumberField = Nz(DMax("NumberField", "YourTable", _
"Year([DateField]) = " & Year([DateField])), 0) + 1
End If

Use your own field and table names, of course.

To display the number, you could do something like this as the Control
Source of an unbound text box:
=Format([DateField],"yy") & "-" & Format([NumberField],"000")

Keep in mind that NumberField cannot be used as the primary key, since it
will start over from 0 each year. If you already have a primary key that
is
not a problem. If this number is to be the primary key you could add the
year to the beginning of the number, but that involves a few more steps,
so
I will wait until I hear more about the details. Some would argue that
adding the year to the number is storing the year redundantly, but
without
that you would need either a compound primary key or a separate primary
key
field.

The general point here is that you can build an automatically
incrementing
number into your database. As always, the details dictate the specifics.

AusTexRich said:
I want to create a numbering system, in a three character format, in a
form
starting at "001" and so on. Now, because the of the formatting of the
prior
data from an Excel file, I've had to distinguish one year's records
from
the
next with a text field "08" (year). So when a new record is added, the
text
"08" is added and then the count begins at "001". How do I do that?

table fields are: [I_period] - "08", [row_num] - "001", "002, etc,.
Thanks all.
 
A

AusTexRich

Hi,
Thanks again for hanging in there with me.

Do you have a date field in the record? Originally no. I'll add one. It
appears best to do so.

Is there a primary key field or combination of fields? No primary key field.

My concern was how to add numbers to a field that had a mishmash of numbers
and text rather than a pure number.

For example...

Field 1 (text)
1
2a
3
3c

I believe from what you given me will work. I'll give it a try anyway

Thanks
--
AusTexRich


BruceM said:
It will start over at 1 next year. Note this part of the code for DMax,
which is the optional criteria:
"Year([DateField]) = " & Year([DateField])
If the DMax statement just included the following:
DMax("NumberField", "YourTable") + 1
then Access would find the largest value for NumberField in YourTable and
add 1 to it.
However, with the optional criteria added:
DMax("NumberField", "YourTable","Year([DateField]) = " & Year([DateField]) +
1
Access will find the largest value for NumberField in YourTable for which
the Year portion of DateField is the same as the Year portion of DateField
for the current record, and add 1 to it.
The Nz in the original code allows for the fact that for the year's first
record there will be no records in which Year from DateField equals Year
from the current record. In that case DMax will produce a null value. Nz
replaces the null with a 0, to which 1 is added, resulting in a value of 1
in NumberField for the first record of any year.
Do you have a date field in the record?
Is there a primary key field or combination of fields?
My original post includes the reasons why I ask these questions. The year
can be added to the number and stored, but first I'm trying to find out if
it's necessary. If it isn't you can just concatenate the two-digit year
with the number as I described.

AusTexRich said:
Hi,
Great stuff. I very appreciative of your help. You guys always have some
great stuff.
My problem is adding new records to a table of preexisting data that is
grouped by year (kind of) and each prior year has its own count beginning
at
001 to the last record for the year.
If I use DMax I get the next record 539. Great for this year, but, what
about next year? I'd like the "counter" to reset to "001".

I was hoping that if I add a text field to capture the year "08" I can
base
a numbering system on that and start at "001".
--
AusTexRich


BruceM said:
Assuming the year is stored somewhere in the record (as part of a date
field), you could do something like this in the After Update event for
the
control bound to the date field:
If Me.NewRecord Then
Me.NumberField = Nz(DMax("NumberField", "YourTable", _
"Year([DateField]) = " & Year([DateField])), 0) + 1
End If

Use your own field and table names, of course.

To display the number, you could do something like this as the Control
Source of an unbound text box:
=Format([DateField],"yy") & "-" & Format([NumberField],"000")

Keep in mind that NumberField cannot be used as the primary key, since it
will start over from 0 each year. If you already have a primary key that
is
not a problem. If this number is to be the primary key you could add the
year to the beginning of the number, but that involves a few more steps,
so
I will wait until I hear more about the details. Some would argue that
adding the year to the number is storing the year redundantly, but
without
that you would need either a compound primary key or a separate primary
key
field.

The general point here is that you can build an automatically
incrementing
number into your database. As always, the details dictate the specifics.

I want to create a numbering system, in a three character format, in a
form
starting at "001" and so on. Now, because the of the formatting of the
prior
data from an Excel file, I've had to distinguish one year's records
from
the
next with a text field "08" (year). So when a new record is added, the
text
"08" is added and then the count begins at "001". How do I do that?

table fields are: [I_period] - "08", [row_num] - "001", "002, etc,.
Thanks all.
 
A

AusTexRich

OK, Bruce M, what you've given me worked just fine.

You're the greatest.

Thank you so much.
--
AusTexRich


AusTexRich said:
Hi,
Thanks again for hanging in there with me.

Do you have a date field in the record? Originally no. I'll add one. It
appears best to do so.

Is there a primary key field or combination of fields? No primary key field.

My concern was how to add numbers to a field that had a mishmash of numbers
and text rather than a pure number.

For example...

Field 1 (text)
1
2a
3
3c

I believe from what you given me will work. I'll give it a try anyway

Thanks
--
AusTexRich


BruceM said:
It will start over at 1 next year. Note this part of the code for DMax,
which is the optional criteria:
"Year([DateField]) = " & Year([DateField])
If the DMax statement just included the following:
DMax("NumberField", "YourTable") + 1
then Access would find the largest value for NumberField in YourTable and
add 1 to it.
However, with the optional criteria added:
DMax("NumberField", "YourTable","Year([DateField]) = " & Year([DateField]) +
1
Access will find the largest value for NumberField in YourTable for which
the Year portion of DateField is the same as the Year portion of DateField
for the current record, and add 1 to it.
The Nz in the original code allows for the fact that for the year's first
record there will be no records in which Year from DateField equals Year
from the current record. In that case DMax will produce a null value. Nz
replaces the null with a 0, to which 1 is added, resulting in a value of 1
in NumberField for the first record of any year.
Do you have a date field in the record?
Is there a primary key field or combination of fields?
My original post includes the reasons why I ask these questions. The year
can be added to the number and stored, but first I'm trying to find out if
it's necessary. If it isn't you can just concatenate the two-digit year
with the number as I described.

AusTexRich said:
Hi,
Great stuff. I very appreciative of your help. You guys always have some
great stuff.
My problem is adding new records to a table of preexisting data that is
grouped by year (kind of) and each prior year has its own count beginning
at
001 to the last record for the year.
If I use DMax I get the next record 539. Great for this year, but, what
about next year? I'd like the "counter" to reset to "001".

I was hoping that if I add a text field to capture the year "08" I can
base
a numbering system on that and start at "001".
--
AusTexRich


:

Assuming the year is stored somewhere in the record (as part of a date
field), you could do something like this in the After Update event for
the
control bound to the date field:
If Me.NewRecord Then
Me.NumberField = Nz(DMax("NumberField", "YourTable", _
"Year([DateField]) = " & Year([DateField])), 0) + 1
End If

Use your own field and table names, of course.

To display the number, you could do something like this as the Control
Source of an unbound text box:
=Format([DateField],"yy") & "-" & Format([NumberField],"000")

Keep in mind that NumberField cannot be used as the primary key, since it
will start over from 0 each year. If you already have a primary key that
is
not a problem. If this number is to be the primary key you could add the
year to the beginning of the number, but that involves a few more steps,
so
I will wait until I hear more about the details. Some would argue that
adding the year to the number is storing the year redundantly, but
without
that you would need either a compound primary key or a separate primary
key
field.

The general point here is that you can build an automatically
incrementing
number into your database. As always, the details dictate the specifics.

I want to create a numbering system, in a three character format, in a
form
starting at "001" and so on. Now, because the of the formatting of the
prior
data from an Excel file, I've had to distinguish one year's records
from
the
next with a text field "08" (year). So when a new record is added, the
text
"08" is added and then the count begins at "001". How do I do that?

table fields are: [I_period] - "08", [row_num] - "001", "002, etc,.
Thanks all.
 
B

BruceM

Glad to hear you got it working. There are ways to create just about any
incrementing number or combination of text and numbers, as long as there are
specific rules to govern the process. By the way, a "mishmash" of text and
numbers is just text. To increment the number portion you would need to
have Access handle it as a number even though it is stored as text. It's
not all that difficult to do, but it does add an extra layer or two to the
code.

AusTexRich said:
OK, Bruce M, what you've given me worked just fine.

You're the greatest.

Thank you so much.
--
AusTexRich


AusTexRich said:
Hi,
Thanks again for hanging in there with me.

Do you have a date field in the record? Originally no. I'll add one.
It
appears best to do so.

Is there a primary key field or combination of fields? No primary key
field.

My concern was how to add numbers to a field that had a mishmash of
numbers
and text rather than a pure number.

For example...

Field 1 (text)
1
2a
3
3c

I believe from what you given me will work. I'll give it a try anyway

Thanks
--
AusTexRich


BruceM said:
It will start over at 1 next year. Note this part of the code for
DMax,
which is the optional criteria:
"Year([DateField]) = " & Year([DateField])
If the DMax statement just included the following:
DMax("NumberField", "YourTable") + 1
then Access would find the largest value for NumberField in YourTable
and
add 1 to it.
However, with the optional criteria added:
DMax("NumberField", "YourTable","Year([DateField]) = " &
Year([DateField]) +
1
Access will find the largest value for NumberField in YourTable for
which
the Year portion of DateField is the same as the Year portion of
DateField
for the current record, and add 1 to it.
The Nz in the original code allows for the fact that for the year's
first
record there will be no records in which Year from DateField equals
Year
from the current record. In that case DMax will produce a null value.
Nz
replaces the null with a 0, to which 1 is added, resulting in a value
of 1
in NumberField for the first record of any year.
Do you have a date field in the record?
Is there a primary key field or combination of fields?
My original post includes the reasons why I ask these questions. The
year
can be added to the number and stored, but first I'm trying to find out
if
it's necessary. If it isn't you can just concatenate the two-digit
year
with the number as I described.

Hi,
Great stuff. I very appreciative of your help. You guys always have
some
great stuff.
My problem is adding new records to a table of preexisting data that
is
grouped by year (kind of) and each prior year has its own count
beginning
at
001 to the last record for the year.
If I use DMax I get the next record 539. Great for this year, but,
what
about next year? I'd like the "counter" to reset to "001".

I was hoping that if I add a text field to capture the year "08" I
can
base
a numbering system on that and start at "001".
--
AusTexRich


:

Assuming the year is stored somewhere in the record (as part of a
date
field), you could do something like this in the After Update event
for
the
control bound to the date field:
If Me.NewRecord Then
Me.NumberField = Nz(DMax("NumberField", "YourTable", _
"Year([DateField]) = " & Year([DateField])), 0) + 1
End If

Use your own field and table names, of course.

To display the number, you could do something like this as the
Control
Source of an unbound text box:
=Format([DateField],"yy") & "-" & Format([NumberField],"000")

Keep in mind that NumberField cannot be used as the primary key,
since it
will start over from 0 each year. If you already have a primary key
that
is
not a problem. If this number is to be the primary key you could
add the
year to the beginning of the number, but that involves a few more
steps,
so
I will wait until I hear more about the details. Some would argue
that
adding the year to the number is storing the year redundantly, but
without
that you would need either a compound primary key or a separate
primary
key
field.

The general point here is that you can build an automatically
incrementing
number into your database. As always, the details dictate the
specifics.

I want to create a numbering system, in a three character format,
in a
form
starting at "001" and so on. Now, because the of the formatting
of the
prior
data from an Excel file, I've had to distinguish one year's
records
from
the
next with a text field "08" (year). So when a new record is
added, the
text
"08" is added and then the count begins at "001". How do I do
that?

table fields are: [I_period] - "08", [row_num] - "001", "002,
etc,.
Thanks all.
 
P

punitha

hey BruceM,

i was looking for the same solution and it worked great for me too. but then
there's only one thing that i'm thinking of...

waht if i have 2 criterias to be considered... like year, which is working
well now... and category i have 2 categories of sample coming "R" & "P" and
they each start with number 0001 in the beginning of each year. do i still
put the code in the DateRec after Update event or the form's?

thank you in advance


BruceM said:
Glad to hear you got it working. There are ways to create just about any
incrementing number or combination of text and numbers, as long as there are
specific rules to govern the process. By the way, a "mishmash" of text and
numbers is just text. To increment the number portion you would need to
have Access handle it as a number even though it is stored as text. It's
not all that difficult to do, but it does add an extra layer or two to the
code.

AusTexRich said:
OK, Bruce M, what you've given me worked just fine.

You're the greatest.

Thank you so much.
--
AusTexRich


AusTexRich said:
Hi,
Thanks again for hanging in there with me.

Do you have a date field in the record? Originally no. I'll add one.
It
appears best to do so.

Is there a primary key field or combination of fields? No primary key
field.

My concern was how to add numbers to a field that had a mishmash of
numbers
and text rather than a pure number.

For example...

Field 1 (text)
1
2a
3
3c

I believe from what you given me will work. I'll give it a try anyway

Thanks
--
AusTexRich


:

It will start over at 1 next year. Note this part of the code for
DMax,
which is the optional criteria:
"Year([DateField]) = " & Year([DateField])
If the DMax statement just included the following:
DMax("NumberField", "YourTable") + 1
then Access would find the largest value for NumberField in YourTable
and
add 1 to it.
However, with the optional criteria added:
DMax("NumberField", "YourTable","Year([DateField]) = " &
Year([DateField]) +
1
Access will find the largest value for NumberField in YourTable for
which
the Year portion of DateField is the same as the Year portion of
DateField
for the current record, and add 1 to it.
The Nz in the original code allows for the fact that for the year's
first
record there will be no records in which Year from DateField equals
Year
from the current record. In that case DMax will produce a null value.
Nz
replaces the null with a 0, to which 1 is added, resulting in a value
of 1
in NumberField for the first record of any year.
Do you have a date field in the record?
Is there a primary key field or combination of fields?
My original post includes the reasons why I ask these questions. The
year
can be added to the number and stored, but first I'm trying to find out
if
it's necessary. If it isn't you can just concatenate the two-digit
year
with the number as I described.

Hi,
Great stuff. I very appreciative of your help. You guys always have
some
great stuff.
My problem is adding new records to a table of preexisting data that
is
grouped by year (kind of) and each prior year has its own count
beginning
at
001 to the last record for the year.
If I use DMax I get the next record 539. Great for this year, but,
what
about next year? I'd like the "counter" to reset to "001".

I was hoping that if I add a text field to capture the year "08" I
can
base
a numbering system on that and start at "001".
--
AusTexRich


:

Assuming the year is stored somewhere in the record (as part of a
date
field), you could do something like this in the After Update event
for
the
control bound to the date field:
If Me.NewRecord Then
Me.NumberField = Nz(DMax("NumberField", "YourTable", _
"Year([DateField]) = " & Year([DateField])), 0) + 1
End If

Use your own field and table names, of course.

To display the number, you could do something like this as the
Control
Source of an unbound text box:
=Format([DateField],"yy") & "-" & Format([NumberField],"000")

Keep in mind that NumberField cannot be used as the primary key,
since it
will start over from 0 each year. If you already have a primary key
that
is
not a problem. If this number is to be the primary key you could
add the
year to the beginning of the number, but that involves a few more
steps,
so
I will wait until I hear more about the details. Some would argue
that
adding the year to the number is storing the year redundantly, but
without
that you would need either a compound primary key or a separate
primary
key
field.

The general point here is that you can build an automatically
incrementing
number into your database. As always, the details dictate the
specifics.

I want to create a numbering system, in a three character format,
in a
form
starting at "001" and so on. Now, because the of the formatting
of the
prior
data from an Excel file, I've had to distinguish one year's
records
from
the
next with a text field "08" (year). So when a new record is
added, the
text
"08" is added and then the count begins at "001". How do I do
that?

table fields are: [I_period] - "08", [row_num] - "001", "002,
etc,.
Thanks all.
 
B

BruceM

You can add another criteria to the Where argument of DMax:

If Me.NewRecord Then
Me.NumberField = Nz(DMax("[NumberField]", "YourTable", _
"Year([DateField]) = " & Year(Date()) _
"And [Category] = """ & Me.Category & """"), 0) + 1
End If

You could place this code in the form's Before Insert event or Current
event.

This assumes that NumberField is the name of the field containing the
incrementing number, and that there is a date field and a Category field
(text) in the form's record source. If the form is based on YourTable
(whatever you have named it), typically DateField and Category would appear
on the form. The expression is saying something like this:
"Find the largest number in NumberField in a record from YourTable where the
year is the same as the current year and the Category is the same as the one
in the current record, and add one to that NumberField value."

In an unbound text box on the form you could have as the Control Source:
= [Category] & Format([NumberField],"0000")

You could instead have the expression in the form's Record Source query:
Combined: [Category] & Format([NumberField],"0000")
then bind a text box to Combined.

Using DefaultValue has some advantages over testing for NewRecord. If the
user backs out without adding any data there is nothing to undo with
DefaultValue, while I believe you would need to undo data created with If
Me.NewRecord. The code would be something like this in the form's Current
or Before Insert event:

Me.txtNumberField.DefaultValue = Nz(DMax("[NumberField]", "YourTable", _
"Year([DateField]) = " & Year(Date()) _
"And [Category] = """ & Me.Category & """"), 0) + 1

Note that txtNumberField is a text box bound to NumberField.

In any case you will need to take precautions against duplicate numbers in a
multi-user environment. One way is to hold off on creating the new number
until the form's Before Update event. In many cases this will be enough.
The form's After Update event is too late, since the update has already
occurred. There are a number of approaches you could take, depending on the
details.

If you have difficulties, post more details of your situation. I had to do
some reading between the lines.


punitha said:
hey BruceM,

i was looking for the same solution and it worked great for me too. but
then
there's only one thing that i'm thinking of...

waht if i have 2 criterias to be considered... like year, which is working
well now... and category i have 2 categories of sample coming "R" & "P"
and
they each start with number 0001 in the beginning of each year. do i still
put the code in the DateRec after Update event or the form's?

thank you in advance


BruceM said:
Glad to hear you got it working. There are ways to create just about any
incrementing number or combination of text and numbers, as long as there
are
specific rules to govern the process. By the way, a "mishmash" of text
and
numbers is just text. To increment the number portion you would need to
have Access handle it as a number even though it is stored as text. It's
not all that difficult to do, but it does add an extra layer or two to
the
code.

AusTexRich said:
OK, Bruce M, what you've given me worked just fine.

You're the greatest.

Thank you so much.
--
AusTexRich


:

Hi,
Thanks again for hanging in there with me.

Do you have a date field in the record? Originally no. I'll add one.
It
appears best to do so.

Is there a primary key field or combination of fields? No primary key
field.

My concern was how to add numbers to a field that had a mishmash of
numbers
and text rather than a pure number.

For example...

Field 1 (text)
1
2a
3
3c

I believe from what you given me will work. I'll give it a try anyway

Thanks
--
AusTexRich


:

It will start over at 1 next year. Note this part of the code for
DMax,
which is the optional criteria:
"Year([DateField]) = " & Year([DateField])
If the DMax statement just included the following:
DMax("NumberField", "YourTable") + 1
then Access would find the largest value for NumberField in
YourTable
and
add 1 to it.
However, with the optional criteria added:
DMax("NumberField", "YourTable","Year([DateField]) = " &
Year([DateField]) +
1
Access will find the largest value for NumberField in YourTable for
which
the Year portion of DateField is the same as the Year portion of
DateField
for the current record, and add 1 to it.
The Nz in the original code allows for the fact that for the year's
first
record there will be no records in which Year from DateField equals
Year
from the current record. In that case DMax will produce a null
value.
Nz
replaces the null with a 0, to which 1 is added, resulting in a
value
of 1
in NumberField for the first record of any year.
Do you have a date field in the record?
Is there a primary key field or combination of fields?
My original post includes the reasons why I ask these questions.
The
year
can be added to the number and stored, but first I'm trying to find
out
if
it's necessary. If it isn't you can just concatenate the two-digit
year
with the number as I described.

Hi,
Great stuff. I very appreciative of your help. You guys always
have
some
great stuff.
My problem is adding new records to a table of preexisting data
that
is
grouped by year (kind of) and each prior year has its own count
beginning
at
001 to the last record for the year.
If I use DMax I get the next record 539. Great for this year, but,
what
about next year? I'd like the "counter" to reset to "001".

I was hoping that if I add a text field to capture the year "08" I
can
base
a numbering system on that and start at "001".
--
AusTexRich


:

Assuming the year is stored somewhere in the record (as part of a
date
field), you could do something like this in the After Update
event
for
the
control bound to the date field:
If Me.NewRecord Then
Me.NumberField = Nz(DMax("NumberField", "YourTable", _
"Year([DateField]) = " & Year([DateField])), 0) + 1
End If

Use your own field and table names, of course.

To display the number, you could do something like this as the
Control
Source of an unbound text box:
=Format([DateField],"yy") & "-" & Format([NumberField],"000")

Keep in mind that NumberField cannot be used as the primary key,
since it
will start over from 0 each year. If you already have a primary
key
that
is
not a problem. If this number is to be the primary key you could
add the
year to the beginning of the number, but that involves a few more
steps,
so
I will wait until I hear more about the details. Some would
argue
that
adding the year to the number is storing the year redundantly,
but
without
that you would need either a compound primary key or a separate
primary
key
field.

The general point here is that you can build an automatically
incrementing
number into your database. As always, the details dictate the
specifics.

message
I want to create a numbering system, in a three character
format,
in a
form
starting at "001" and so on. Now, because the of the
formatting
of the
prior
data from an Excel file, I've had to distinguish one year's
records
from
the
next with a text field "08" (year). So when a new record is
added, the
text
"08" is added and then the count begins at "001". How do I do
that?

table fields are: [I_period] - "08", [row_num] - "001", "002,
etc,.
Thanks all.
 
P

punitha

hi,
thanx alot for ur prompt reply

i tried the DefaultValue code in Form Current event.
i'm getting Compile error msg; Expected: list separator or ), highlighting
"And [Category] = """

sorry i'm a newbie when it comes to codes...

thanx again



BruceM said:
You can add another criteria to the Where argument of DMax:

If Me.NewRecord Then
Me.NumberField = Nz(DMax("[NumberField]", "YourTable", _
"Year([DateField]) = " & Year(Date()) _
"And [Category] = """ & Me.Category & """"), 0) + 1
End If

You could place this code in the form's Before Insert event or Current
event.

This assumes that NumberField is the name of the field containing the
incrementing number, and that there is a date field and a Category field
(text) in the form's record source. If the form is based on YourTable
(whatever you have named it), typically DateField and Category would appear
on the form. The expression is saying something like this:
"Find the largest number in NumberField in a record from YourTable where the
year is the same as the current year and the Category is the same as the one
in the current record, and add one to that NumberField value."

In an unbound text box on the form you could have as the Control Source:
= [Category] & Format([NumberField],"0000")

You could instead have the expression in the form's Record Source query:
Combined: [Category] & Format([NumberField],"0000")
then bind a text box to Combined.

Using DefaultValue has some advantages over testing for NewRecord. If the
user backs out without adding any data there is nothing to undo with
DefaultValue, while I believe you would need to undo data created with If
Me.NewRecord. The code would be something like this in the form's Current
or Before Insert event:

Me.txtNumberField.DefaultValue = Nz(DMax("[NumberField]", "YourTable", _
"Year([DateField]) = " & Year(Date()) _
"And [Category] = """ & Me.Category & """"), 0) + 1

Note that txtNumberField is a text box bound to NumberField.

In any case you will need to take precautions against duplicate numbers in a
multi-user environment. One way is to hold off on creating the new number
until the form's Before Update event. In many cases this will be enough.
The form's After Update event is too late, since the update has already
occurred. There are a number of approaches you could take, depending on the
details.

If you have difficulties, post more details of your situation. I had to do
some reading between the lines.


punitha said:
hey BruceM,

i was looking for the same solution and it worked great for me too. but
then
there's only one thing that i'm thinking of...

waht if i have 2 criterias to be considered... like year, which is working
well now... and category i have 2 categories of sample coming "R" & "P"
and
they each start with number 0001 in the beginning of each year. do i still
put the code in the DateRec after Update event or the form's?

thank you in advance


BruceM said:
Glad to hear you got it working. There are ways to create just about any
incrementing number or combination of text and numbers, as long as there
are
specific rules to govern the process. By the way, a "mishmash" of text
and
numbers is just text. To increment the number portion you would need to
have Access handle it as a number even though it is stored as text. It's
not all that difficult to do, but it does add an extra layer or two to
the
code.

OK, Bruce M, what you've given me worked just fine.

You're the greatest.

Thank you so much.
--
AusTexRich


:

Hi,
Thanks again for hanging in there with me.

Do you have a date field in the record? Originally no. I'll add one.
It
appears best to do so.

Is there a primary key field or combination of fields? No primary key
field.

My concern was how to add numbers to a field that had a mishmash of
numbers
and text rather than a pure number.

For example...

Field 1 (text)
1
2a
3
3c

I believe from what you given me will work. I'll give it a try anyway

Thanks
--
AusTexRich


:

It will start over at 1 next year. Note this part of the code for
DMax,
which is the optional criteria:
"Year([DateField]) = " & Year([DateField])
If the DMax statement just included the following:
DMax("NumberField", "YourTable") + 1
then Access would find the largest value for NumberField in
YourTable
and
add 1 to it.
However, with the optional criteria added:
DMax("NumberField", "YourTable","Year([DateField]) = " &
Year([DateField]) +
1
Access will find the largest value for NumberField in YourTable for
which
the Year portion of DateField is the same as the Year portion of
DateField
for the current record, and add 1 to it.
The Nz in the original code allows for the fact that for the year's
first
record there will be no records in which Year from DateField equals
Year
from the current record. In that case DMax will produce a null
value.
Nz
replaces the null with a 0, to which 1 is added, resulting in a
value
of 1
in NumberField for the first record of any year.
Do you have a date field in the record?
Is there a primary key field or combination of fields?
My original post includes the reasons why I ask these questions.
The
year
can be added to the number and stored, but first I'm trying to find
out
if
it's necessary. If it isn't you can just concatenate the two-digit
year
with the number as I described.

Hi,
Great stuff. I very appreciative of your help. You guys always
have
some
great stuff.
My problem is adding new records to a table of preexisting data
that
is
grouped by year (kind of) and each prior year has its own count
beginning
at
001 to the last record for the year.
If I use DMax I get the next record 539. Great for this year, but,
what
about next year? I'd like the "counter" to reset to "001".

I was hoping that if I add a text field to capture the year "08" I
can
base
a numbering system on that and start at "001".
--
AusTexRich


:

Assuming the year is stored somewhere in the record (as part of a
date
field), you could do something like this in the After Update
event
for
the
control bound to the date field:
If Me.NewRecord Then
Me.NumberField = Nz(DMax("NumberField", "YourTable", _
"Year([DateField]) = " & Year([DateField])), 0) + 1
End If

Use your own field and table names, of course.

To display the number, you could do something like this as the
Control
Source of an unbound text box:
=Format([DateField],"yy") & "-" & Format([NumberField],"000")

Keep in mind that NumberField cannot be used as the primary key,
since it
will start over from 0 each year. If you already have a primary
key
that
is
not a problem. If this number is to be the primary key you could
add the
year to the beginning of the number, but that involves a few more
steps,
so
I will wait until I hear more about the details. Some would
argue
that
adding the year to the number is storing the year redundantly,
but
without
that you would need either a compound primary key or a separate
primary
key
field.

The general point here is that you can build an automatically
incrementing
number into your database. As always, the details dictate the
specifics.

message
I want to create a numbering system, in a three character
format,
in a
form
starting at "001" and so on. Now, because the of the
formatting
of the
prior
data from an Excel file, I've had to distinguish one year's
records
from
the
next with a text field "08" (year). So when a new record is
added, the
text
"08" is added and then the count begins at "001". How do I do
that?

table fields are: [I_period] - "08", [row_num] - "001", "002,
etc,.
Thanks all.
 
P

punitha

when i put it this way:

"Year([DateRec]) = " & Year(Date), "And ([Category]) = """ & Me.cboCategory
& """"), 0) + 1

it says: wrong number of arguments or invalid property assingment,
highlighting DMax

pls help


BruceM said:
You can add another criteria to the Where argument of DMax:

If Me.NewRecord Then
Me.NumberField = Nz(DMax("[NumberField]", "YourTable", _
"Year([DateField]) = " & Year(Date()) _
"And [Category] = """ & Me.Category & """"), 0) + 1
End If

You could place this code in the form's Before Insert event or Current
event.

This assumes that NumberField is the name of the field containing the
incrementing number, and that there is a date field and a Category field
(text) in the form's record source. If the form is based on YourTable
(whatever you have named it), typically DateField and Category would appear
on the form. The expression is saying something like this:
"Find the largest number in NumberField in a record from YourTable where the
year is the same as the current year and the Category is the same as the one
in the current record, and add one to that NumberField value."

In an unbound text box on the form you could have as the Control Source:
= [Category] & Format([NumberField],"0000")

You could instead have the expression in the form's Record Source query:
Combined: [Category] & Format([NumberField],"0000")
then bind a text box to Combined.

Using DefaultValue has some advantages over testing for NewRecord. If the
user backs out without adding any data there is nothing to undo with
DefaultValue, while I believe you would need to undo data created with If
Me.NewRecord. The code would be something like this in the form's Current
or Before Insert event:

Me.txtNumberField.DefaultValue = Nz(DMax("[NumberField]", "YourTable", _
"Year([DateField]) = " & Year(Date()) _
"And [Category] = """ & Me.Category & """"), 0) + 1

Note that txtNumberField is a text box bound to NumberField.

In any case you will need to take precautions against duplicate numbers in a
multi-user environment. One way is to hold off on creating the new number
until the form's Before Update event. In many cases this will be enough.
The form's After Update event is too late, since the update has already
occurred. There are a number of approaches you could take, depending on the
details.

If you have difficulties, post more details of your situation. I had to do
some reading between the lines.


punitha said:
hey BruceM,

i was looking for the same solution and it worked great for me too. but
then
there's only one thing that i'm thinking of...

waht if i have 2 criterias to be considered... like year, which is working
well now... and category i have 2 categories of sample coming "R" & "P"
and
they each start with number 0001 in the beginning of each year. do i still
put the code in the DateRec after Update event or the form's?

thank you in advance


BruceM said:
Glad to hear you got it working. There are ways to create just about any
incrementing number or combination of text and numbers, as long as there
are
specific rules to govern the process. By the way, a "mishmash" of text
and
numbers is just text. To increment the number portion you would need to
have Access handle it as a number even though it is stored as text. It's
not all that difficult to do, but it does add an extra layer or two to
the
code.

OK, Bruce M, what you've given me worked just fine.

You're the greatest.

Thank you so much.
--
AusTexRich


:

Hi,
Thanks again for hanging in there with me.

Do you have a date field in the record? Originally no. I'll add one.
It
appears best to do so.

Is there a primary key field or combination of fields? No primary key
field.

My concern was how to add numbers to a field that had a mishmash of
numbers
and text rather than a pure number.

For example...

Field 1 (text)
1
2a
3
3c

I believe from what you given me will work. I'll give it a try anyway

Thanks
--
AusTexRich


:

It will start over at 1 next year. Note this part of the code for
DMax,
which is the optional criteria:
"Year([DateField]) = " & Year([DateField])
If the DMax statement just included the following:
DMax("NumberField", "YourTable") + 1
then Access would find the largest value for NumberField in
YourTable
and
add 1 to it.
However, with the optional criteria added:
DMax("NumberField", "YourTable","Year([DateField]) = " &
Year([DateField]) +
1
Access will find the largest value for NumberField in YourTable for
which
the Year portion of DateField is the same as the Year portion of
DateField
for the current record, and add 1 to it.
The Nz in the original code allows for the fact that for the year's
first
record there will be no records in which Year from DateField equals
Year
from the current record. In that case DMax will produce a null
value.
Nz
replaces the null with a 0, to which 1 is added, resulting in a
value
of 1
in NumberField for the first record of any year.
Do you have a date field in the record?
Is there a primary key field or combination of fields?
My original post includes the reasons why I ask these questions.
The
year
can be added to the number and stored, but first I'm trying to find
out
if
it's necessary. If it isn't you can just concatenate the two-digit
year
with the number as I described.

Hi,
Great stuff. I very appreciative of your help. You guys always
have
some
great stuff.
My problem is adding new records to a table of preexisting data
that
is
grouped by year (kind of) and each prior year has its own count
beginning
at
001 to the last record for the year.
If I use DMax I get the next record 539. Great for this year, but,
what
about next year? I'd like the "counter" to reset to "001".

I was hoping that if I add a text field to capture the year "08" I
can
base
a numbering system on that and start at "001".
--
AusTexRich


:

Assuming the year is stored somewhere in the record (as part of a
date
field), you could do something like this in the After Update
event
for
the
control bound to the date field:
If Me.NewRecord Then
Me.NumberField = Nz(DMax("NumberField", "YourTable", _
"Year([DateField]) = " & Year([DateField])), 0) + 1
End If

Use your own field and table names, of course.

To display the number, you could do something like this as the
Control
Source of an unbound text box:
=Format([DateField],"yy") & "-" & Format([NumberField],"000")

Keep in mind that NumberField cannot be used as the primary key,
since it
will start over from 0 each year. If you already have a primary
key
that
is
not a problem. If this number is to be the primary key you could
add the
year to the beginning of the number, but that involves a few more
steps,
so
I will wait until I hear more about the details. Some would
argue
that
adding the year to the number is storing the year redundantly,
but
without
that you would need either a compound primary key or a separate
primary
key
field.

The general point here is that you can build an automatically
incrementing
number into your database. As always, the details dictate the
specifics.

message
I want to create a numbering system, in a three character
format,
in a
form
starting at "001" and so on. Now, because the of the
formatting
of the
prior
data from an Excel file, I've had to distinguish one year's
records
from
the
next with a text field "08" (year). So when a new record is
added, the
text
"08" is added and then the count begins at "001". How do I do
that?

table fields are: [I_period] - "08", [row_num] - "001", "002,
etc,.
Thanks all.
 
J

John W. Vinson

when i put it this way:

"Year([DateRec]) = " & Year(Date), "And ([Category]) = """ & Me.cboCategory
& """"), 0) + 1

it says: wrong number of arguments or invalid property assingment,
highlighting DMax

Leave out the comma after Year(Date).

It would really help if you would post the entire block of code, not just one
continuation line; it would help to understand the context!
 
P

punitha

sorry abt that.

this is the code i'm using:

Me.txtLabNo.DefaultValue = Nz(DMax("[LabNo]", "SampleDetail", _
"Year([DateRec]) = " & Year(Date) "And ([Category]) = """ &
Me.cboCategory & """"), 0) + 1

i'm getting Compile error msg; Expected: list separator or ), highlighting
"And [Category] = """



John W. Vinson said:
when i put it this way:

"Year([DateRec]) = " & Year(Date), "And ([Category]) = """ & Me.cboCategory
& """"), 0) + 1

it says: wrong number of arguments or invalid property assingment,
highlighting DMax

Leave out the comma after Year(Date).

It would really help if you would post the entire block of code, not just one
continuation line; it would help to understand the context!
 
B

BruceM

I posted the code late in the day, and did not proofread it very well.
There needs to be an ampersand between Year(Date()) and the word "And":
Me.txtLabNo.DefaultValue = Nz(DMax("[LabNo]", "SampleDetail", _
"Year([DateRec]) = " & Year(Date()) & _
" And [Category] = """ & Me.cboCategory & """"), 0) + 1

The ampersand I mentioned is the list separator referred to in the error
message, I think.

Also, I removed the parentheses from around [Category]. I don't know if
that matters or not, but it is at best unnecessary. There are parentheses
after Year because Year is a function that extracts the year from a
Date/Time value. There are also parentheses after Date, since that is a
function that returns the current date. The VBA editor may remove those
automatically, which is fine. Help has more information about these
functions, as well as Nz and DMax. Help should also have information about
DefaultValue, which is a property.

You can test the Where condition by adding this to the code, just before the
code you posted:

Debug.Print "Year([DateRec]) = " & Year(Date()) & _
" And [Category] = """ & Me.cboCategory & """"

After you run the code, press Ctrl + G, which will open the VBA editor.
Look for the Immediate window and see what is printed there. When the code
is working correctly it should be something like:
Year([DateRec]) = 2008 And [Category] = "R"
You can remove the Debug.Print line after you get the code working as it
should.

Note that the underscore is used as a line break. The code ignores it
otherwise. The ampersand lets you combine dissimilar data. If you place
Year(Date()) within the quotes you would have:
Year([DateRec]) = Year(Date()) And [Category] = "R"

There is more about quotes within quotes here:
http://allenbrowne.com/casu-17.html

punitha said:
sorry abt that.

this is the code i'm using:

Me.txtLabNo.DefaultValue = Nz(DMax("[LabNo]", "SampleDetail", _
"Year([DateRec]) = " & Year(Date) "And ([Category]) = """ &
Me.cboCategory & """"), 0) + 1

i'm getting Compile error msg; Expected: list separator or ), highlighting
"And [Category] = """



John W. Vinson said:
when i put it this way:

"Year([DateRec]) = " & Year(Date), "And ([Category]) = """ &
Me.cboCategory
& """"), 0) + 1

it says: wrong number of arguments or invalid property assingment,
highlighting DMax

Leave out the comma after Year(Date).

It would really help if you would post the entire block of code, not just
one
continuation line; it would help to understand the context!
 
P

punitha

thanx very much u guys.

i didnt get it cos there were some mistakes i can't identify as yet. anyway
this is the code that i used:

dim strCriteria As String
If Me.NewRecord Then
strCriteria = "Year([DateRec]) = " & Year(Me.txtDateRec) & " And
[Category] = '" & Me.cboCategory & "'"
Me.txtLabNo = Nz(DMax("[LabNo]", "SampleDetail", strCriteria), 0) + 1
End If

ur suggestions helped me alot BruceM. i looked into VBA help. thank God u
gyus r around to help ppl like me. i can just kiss u guys rite now... :)

thanks again

BruceM said:
I posted the code late in the day, and did not proofread it very well.
There needs to be an ampersand between Year(Date()) and the word "And":
Me.txtLabNo.DefaultValue = Nz(DMax("[LabNo]", "SampleDetail", _
"Year([DateRec]) = " & Year(Date()) & _
" And [Category] = """ & Me.cboCategory & """"), 0) + 1

The ampersand I mentioned is the list separator referred to in the error
message, I think.

Also, I removed the parentheses from around [Category]. I don't know if
that matters or not, but it is at best unnecessary. There are parentheses
after Year because Year is a function that extracts the year from a
Date/Time value. There are also parentheses after Date, since that is a
function that returns the current date. The VBA editor may remove those
automatically, which is fine. Help has more information about these
functions, as well as Nz and DMax. Help should also have information about
DefaultValue, which is a property.

You can test the Where condition by adding this to the code, just before the
code you posted:

Debug.Print "Year([DateRec]) = " & Year(Date()) & _
" And [Category] = """ & Me.cboCategory & """"

After you run the code, press Ctrl + G, which will open the VBA editor.
Look for the Immediate window and see what is printed there. When the code
is working correctly it should be something like:
Year([DateRec]) = 2008 And [Category] = "R"
You can remove the Debug.Print line after you get the code working as it
should.

Note that the underscore is used as a line break. The code ignores it
otherwise. The ampersand lets you combine dissimilar data. If you place
Year(Date()) within the quotes you would have:
Year([DateRec]) = Year(Date()) And [Category] = "R"

There is more about quotes within quotes here:
http://allenbrowne.com/casu-17.html

punitha said:
sorry abt that.

this is the code i'm using:

Me.txtLabNo.DefaultValue = Nz(DMax("[LabNo]", "SampleDetail", _
"Year([DateRec]) = " & Year(Date) "And ([Category]) = """ &
Me.cboCategory & """"), 0) + 1

i'm getting Compile error msg; Expected: list separator or ), highlighting
"And [Category] = """



John W. Vinson said:
On Tue, 16 Dec 2008 21:12:00 -0800, punitha

when i put it this way:

"Year([DateRec]) = " & Year(Date), "And ([Category]) = """ &
Me.cboCategory
& """"), 0) + 1

it says: wrong number of arguments or invalid property assingment,
highlighting DMax

Leave out the comma after Year(Date).

It would really help if you would post the entire block of code, not just
one
continuation line; it would help to understand the context!
 
B

BruceM

If it is not working, break it down into smaller units. For instance, leave
out the Where (strCriteria) from the DMax, and see if you get the DMax
statement to find the next highest number. If that works, try something
like this as strCriteria:
strCriteria = "Year([DateRec]) = " & 2008
If that works:
MsgBox Year(Me.txtDateRec) ' make sure you are getting the correct value
strCriteria = "Year([DateRec]) = " & Year(Me.txtDateRec)
Next try:
MsgBox Me.cboCategory
strCriteria = "[Category] = '" & Me.cboCategory & "'"

The MsgBox is an alternative to Debug.Print, which I described in the
previous post. Either will work, depending on whether you want to see the
results as you go. Anothe thing you can do is place a break point in the
code. Click the vertical bar to the left of the code window next to the
strCriteria = etc. line of code. The code will stop when it reaches that
line. You can step through the code by pressing the F8 key. As you pass
each line of code you can point to, say, Me.cboCategory to see its value.

These are some of the techniques you can use to troubleshoot code after you
are sure it compiles correctly (Debug >> Compile on the menu bar).

punitha said:
thanx very much u guys.

i didnt get it cos there were some mistakes i can't identify as yet.
anyway
this is the code that i used:

dim strCriteria As String
If Me.NewRecord Then
strCriteria = "Year([DateRec]) = " & Year(Me.txtDateRec) & " And
[Category] = '" & Me.cboCategory & "'"
Me.txtLabNo = Nz(DMax("[LabNo]", "SampleDetail", strCriteria), 0) + 1
End If

ur suggestions helped me alot BruceM. i looked into VBA help. thank God u
gyus r around to help ppl like me. i can just kiss u guys rite now... :)

thanks again

BruceM said:
I posted the code late in the day, and did not proofread it very well.
There needs to be an ampersand between Year(Date()) and the word "And":
Me.txtLabNo.DefaultValue = Nz(DMax("[LabNo]", "SampleDetail", _
"Year([DateRec]) = " & Year(Date()) & _
" And [Category] = """ & Me.cboCategory & """"), 0) + 1

The ampersand I mentioned is the list separator referred to in the error
message, I think.

Also, I removed the parentheses from around [Category]. I don't know if
that matters or not, but it is at best unnecessary. There are
parentheses
after Year because Year is a function that extracts the year from a
Date/Time value. There are also parentheses after Date, since that is a
function that returns the current date. The VBA editor may remove those
automatically, which is fine. Help has more information about these
functions, as well as Nz and DMax. Help should also have information
about
DefaultValue, which is a property.

You can test the Where condition by adding this to the code, just before
the
code you posted:

Debug.Print "Year([DateRec]) = " & Year(Date()) & _
" And [Category] = """ & Me.cboCategory & """"

After you run the code, press Ctrl + G, which will open the VBA editor.
Look for the Immediate window and see what is printed there. When the
code
is working correctly it should be something like:
Year([DateRec]) = 2008 And [Category] = "R"
You can remove the Debug.Print line after you get the code working as it
should.

Note that the underscore is used as a line break. The code ignores it
otherwise. The ampersand lets you combine dissimilar data. If you place
Year(Date()) within the quotes you would have:
Year([DateRec]) = Year(Date()) And [Category] = "R"

There is more about quotes within quotes here:
http://allenbrowne.com/casu-17.html

punitha said:
sorry abt that.

this is the code i'm using:

Me.txtLabNo.DefaultValue = Nz(DMax("[LabNo]", "SampleDetail", _
"Year([DateRec]) = " & Year(Date) "And ([Category]) = """ &
Me.cboCategory & """"), 0) + 1

i'm getting Compile error msg; Expected: list separator or ),
highlighting
"And [Category] = """



:

On Tue, 16 Dec 2008 21:12:00 -0800, punitha

when i put it this way:

"Year([DateRec]) = " & Year(Date), "And ([Category]) = """ &
Me.cboCategory
& """"), 0) + 1

it says: wrong number of arguments or invalid property assingment,
highlighting DMax

Leave out the comma after Year(Date).

It would really help if you would post the entire block of code, not
just
one
continuation line; it would help to understand the context!
 

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