DCOUNT format question

G

Guest

I can get this to work in a totals query but not on a form.

I have this for the control source:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=me.reqdate AND initials
=me.initials")+1

Do I have the format wrong? I'm looking to return the count value and then
concatenate the 3 parts of the Ref#.


I want my db to generate our reference # automatically based on input from
other fields. The number is the date record entered, the users initials, and
an incremental number. Ex. 120505GMM02

My form is based on a query and I have the query generating the first two
components from the date entered in reqdate and the initials entered. How can
I get an incremental number generated to go with the rest.

The number should start with 01 for each day and also for each user.
Therefore when GMM is entering his third record on the 5th it should generate
120505GMM03 even if there were 10 other records entered on the fifth by other
users. Each users numbers would start at 01 for each day.

Thanks.
 
D

Douglas J. Steele

Yes, your format is incorrect.

The values you're checking need to go outside of the quotes. Additional,
dates must be delimited with # (and in mm/dd/yyyy format, regardless of what
your short date format has been set to through Regional Settings)*, and
strings with quotes.

Try the following:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" & Format(me.reqdate,
\#mm\/dd\/yyyy\#") & " AND initials = '" me.initials & "'")+1

Note that, exagerated for clarity, that last bit is:

& " AND initials = ' " me.initials & " ' "

* Okay, so it's not absolutely necessary to use mm/dd/yyyy format. You can
use any unambiguous format, such as yyyy-mm-dd or dd mmm yyyy. The point is,
you can't use dd/mm/yyyy, even if that's what your short date format has
been set to.
 
G

Guest

Douglas,

Thanks for your reply.

When I enter your string into the control on the form, I receive this error:

The expression you entered contains invalid syntax.
You may have entered a comma without a preceding value or identifier.

Thanks.

Douglas J. Steele said:
Yes, your format is incorrect.

The values you're checking need to go outside of the quotes. Additional,
dates must be delimited with # (and in mm/dd/yyyy format, regardless of what
your short date format has been set to through Regional Settings)*, and
strings with quotes.

Try the following:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" & Format(me.reqdate,
\#mm\/dd\/yyyy\#") & " AND initials = '" me.initials & "'")+1

Note that, exagerated for clarity, that last bit is:

& " AND initials = ' " me.initials & " ' "

* Okay, so it's not absolutely necessary to use mm/dd/yyyy format. You can
use any unambiguous format, such as yyyy-mm-dd or dd mmm yyyy. The point is,
you can't use dd/mm/yyyy, even if that's what your short date format has
been set to.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Gary said:
I can get this to work in a totals query but not on a form.

I have this for the control source:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=me.reqdate AND initials
=me.initials")+1

Do I have the format wrong? I'm looking to return the count value and then
concatenate the 3 parts of the Ref#.


I want my db to generate our reference # automatically based on input from
other fields. The number is the date record entered, the users initials,
and
an incremental number. Ex. 120505GMM02

My form is based on a query and I have the query generating the first two
components from the date entered in reqdate and the initials entered. How
can
I get an incremental number generated to go with the rest.

The number should start with 01 for each day and also for each user.
Therefore when GMM is entering his third record on the 5th it should
generate
120505GMM03 even if there were 10 other records entered on the fifth by
other
users. Each users numbers would start at 01 for each day.

Thanks.
 
J

John Spencer

I think Doug must have been tired. He missed an opening quote mark before
the date format and an ampersand between "initials =" and "me.initials"

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,"\#mm\/dd\/yyyy\#") & " AND initials = '" & me.initials &
"'")+1


Gary said:
Douglas,

Thanks for your reply.

When I enter your string into the control on the form, I receive this
error:

The expression you entered contains invalid syntax.
You may have entered a comma without a preceding value or identifier.

Thanks.

Douglas J. Steele said:
Yes, your format is incorrect.

The values you're checking need to go outside of the quotes. Additional,
dates must be delimited with # (and in mm/dd/yyyy format, regardless of
what
your short date format has been set to through Regional Settings)*, and
strings with quotes.

Try the following:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" & Format(me.reqdate,
\#mm\/dd\/yyyy\#") & " AND initials = '" me.initials & "'")+1

Note that, exagerated for clarity, that last bit is:

& " AND initials = ' " me.initials & " ' "

* Okay, so it's not absolutely necessary to use mm/dd/yyyy format. You
can
use any unambiguous format, such as yyyy-mm-dd or dd mmm yyyy. The point
is,
you can't use dd/mm/yyyy, even if that's what your short date format has
been set to.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Gary said:
I can get this to work in a totals query but not on a form.

I have this for the control source:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=me.reqdate AND
initials
=me.initials")+1

Do I have the format wrong? I'm looking to return the count value and
then
concatenate the 3 parts of the Ref#.


I want my db to generate our reference # automatically based on input
from
other fields. The number is the date record entered, the users
initials,
and
an incremental number. Ex. 120505GMM02

My form is based on a query and I have the query generating the first
two
components from the date entered in reqdate and the initials entered.
How
can
I get an incremental number generated to go with the rest.

The number should start with 01 for each day and also for each user.
Therefore when GMM is entering his third record on the 5th it should
generate
120505GMM03 even if there were 10 other records entered on the fifth by
other
users. Each users numbers would start at 01 for each day.

Thanks.
 
J

John Spencer

Can the users delete records?

Iin other words if I had
120505JPS01
120505JPS02
120505JPS03
120505JPS04

And deleted 120505JPS02 then the formula above would generate 4 as the next
number. I would then be trying to create a reference ID of
120505JPS04 when that reference ID already existed.

A better design would be to store the three parts of your reference ID in
separate fields. You can combine them as needed but you would have a lot
more flexibility in searching for references ID, creating reports, etc.


John Spencer said:
I think Doug must have been tired. He missed an opening quote mark before
the date format and an ampersand between "initials =" and "me.initials"

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,"\#mm\/dd\/yyyy\#") & " AND initials = '" & me.initials
& "'")+1


Gary said:
Douglas,

Thanks for your reply.

When I enter your string into the control on the form, I receive this
error:

The expression you entered contains invalid syntax.
You may have entered a comma without a preceding value or identifier.

Thanks.

Douglas J. Steele said:
Yes, your format is incorrect.

The values you're checking need to go outside of the quotes. Additional,
dates must be delimited with # (and in mm/dd/yyyy format, regardless of
what
your short date format has been set to through Regional Settings)*, and
strings with quotes.

Try the following:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,
\#mm\/dd\/yyyy\#") & " AND initials = '" me.initials & "'")+1

Note that, exagerated for clarity, that last bit is:

& " AND initials = ' " me.initials & " ' "

* Okay, so it's not absolutely necessary to use mm/dd/yyyy format. You
can
use any unambiguous format, such as yyyy-mm-dd or dd mmm yyyy. The point
is,
you can't use dd/mm/yyyy, even if that's what your short date format has
been set to.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



I can get this to work in a totals query but not on a form.

I have this for the control source:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=me.reqdate AND
initials
=me.initials")+1

Do I have the format wrong? I'm looking to return the count value and
then
concatenate the 3 parts of the Ref#.


I want my db to generate our reference # automatically based on input
from
other fields. The number is the date record entered, the users
initials,
and
an incremental number. Ex.

My form is based on a query and I have the query generating the first
two
components from the date entered in reqdate and the initials entered.
How
can
I get an incremental number generated to go with the rest.

The number should start with 01 for each day and also for each user.
Therefore when GMM is entering his third record on the 5th it should
generate
120505GMM03 even if there were 10 other records entered on the fifth
by
other
users. Each users numbers would start at 01 for each day.

Thanks.
 
G

Guest

John,

They can delete records but only if entered in error, as if the record never
existed, therefore the next number would rightly be 4.

I will, however, take your advice on how to store it .

Thanks.

Gary

John Spencer said:
Can the users delete records?

Iin other words if I had
120505JPS01
120505JPS02
120505JPS03
120505JPS04

And deleted 120505JPS02 then the formula above would generate 4 as the next
number. I would then be trying to create a reference ID of
120505JPS04 when that reference ID already existed.

A better design would be to store the three parts of your reference ID in
separate fields. You can combine them as needed but you would have a lot
more flexibility in searching for references ID, creating reports, etc.


John Spencer said:
I think Doug must have been tired. He missed an opening quote mark before
the date format and an ampersand between "initials =" and "me.initials"

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,"\#mm\/dd\/yyyy\#") & " AND initials = '" & me.initials
& "'")+1


Gary said:
Douglas,

Thanks for your reply.

When I enter your string into the control on the form, I receive this
error:

The expression you entered contains invalid syntax.
You may have entered a comma without a preceding value or identifier.

Thanks.

:

Yes, your format is incorrect.

The values you're checking need to go outside of the quotes. Additional,
dates must be delimited with # (and in mm/dd/yyyy format, regardless of
what
your short date format has been set to through Regional Settings)*, and
strings with quotes.

Try the following:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,
\#mm\/dd\/yyyy\#") & " AND initials = '" me.initials & "'")+1

Note that, exagerated for clarity, that last bit is:

& " AND initials = ' " me.initials & " ' "

* Okay, so it's not absolutely necessary to use mm/dd/yyyy format. You
can
use any unambiguous format, such as yyyy-mm-dd or dd mmm yyyy. The point
is,
you can't use dd/mm/yyyy, even if that's what your short date format has
been set to.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



I can get this to work in a totals query but not on a form.

I have this for the control source:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=me.reqdate AND
initials
=me.initials")+1

Do I have the format wrong? I'm looking to return the count value and
then
concatenate the 3 parts of the Ref#.


I want my db to generate our reference # automatically based on input
from
other fields. The number is the date record entered, the users
initials,
and
an incremental number. Ex.

My form is based on a query and I have the query generating the first
two
components from the date entered in reqdate and the initials entered.
How
can
I get an incremental number generated to go with the rest.

The number should start with 01 for each day and also for each user.
Therefore when GMM is entering his third record on the 5th it should
generate
120505GMM03 even if there were 10 other records entered on the fifth
by
other
users. Each users numbers would start at 01 for each day.

Thanks.
 
G

Guest

John,

When I place this in the control I get a #NAME? error:

=DCount("[incr]","pickupreqdata","[reqdate]=" &
Format(me.reqdate,"\#mm\/dd\/yyyy\#") & " AND initials = '" & me.initials &
"'")+1

The only things I changed from your string was the field to count (from
Initials to INCR) and from the form name to the table name.

Gary

John Spencer said:
I think Doug must have been tired. He missed an opening quote mark before
the date format and an ampersand between "initials =" and "me.initials"

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,"\#mm\/dd\/yyyy\#") & " AND initials = '" & me.initials &
"'")+1


Gary said:
Douglas,

Thanks for your reply.

When I enter your string into the control on the form, I receive this
error:

The expression you entered contains invalid syntax.
You may have entered a comma without a preceding value or identifier.

Thanks.

Douglas J. Steele said:
Yes, your format is incorrect.

The values you're checking need to go outside of the quotes. Additional,
dates must be delimited with # (and in mm/dd/yyyy format, regardless of
what
your short date format has been set to through Regional Settings)*, and
strings with quotes.

Try the following:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" & Format(me.reqdate,
\#mm\/dd\/yyyy\#") & " AND initials = '" me.initials & "'")+1

Note that, exagerated for clarity, that last bit is:

& " AND initials = ' " me.initials & " ' "

* Okay, so it's not absolutely necessary to use mm/dd/yyyy format. You
can
use any unambiguous format, such as yyyy-mm-dd or dd mmm yyyy. The point
is,
you can't use dd/mm/yyyy, even if that's what your short date format has
been set to.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



I can get this to work in a totals query but not on a form.

I have this for the control source:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=me.reqdate AND
initials
=me.initials")+1

Do I have the format wrong? I'm looking to return the count value and
then
concatenate the 3 parts of the Ref#.


I want my db to generate our reference # automatically based on input
from
other fields. The number is the date record entered, the users
initials,
and
an incremental number. Ex. 120505GMM02

My form is based on a query and I have the query generating the first
two
components from the date entered in reqdate and the initials entered.
How
can
I get an incremental number generated to go with the rest.

The number should start with 01 for each day and also for each user.
Therefore when GMM is entering his third record on the 5th it should
generate
120505GMM03 even if there were 10 other records entered on the fifth by
other
users. Each users numbers would start at 01 for each day.

Thanks.
 
D

Douglas J. Steele

Thanks, John.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



John Spencer said:
I think Doug must have been tired. He missed an opening quote mark before
the date format and an ampersand between "initials =" and "me.initials"

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,"\#mm\/dd\/yyyy\#") & " AND initials = '" & me.initials
& "'")+1


Gary said:
Douglas,

Thanks for your reply.

When I enter your string into the control on the form, I receive this
error:

The expression you entered contains invalid syntax.
You may have entered a comma without a preceding value or identifier.

Thanks.

Douglas J. Steele said:
Yes, your format is incorrect.

The values you're checking need to go outside of the quotes. Additional,
dates must be delimited with # (and in mm/dd/yyyy format, regardless of
what
your short date format has been set to through Regional Settings)*, and
strings with quotes.

Try the following:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,
\#mm\/dd\/yyyy\#") & " AND initials = '" me.initials & "'")+1

Note that, exagerated for clarity, that last bit is:

& " AND initials = ' " me.initials & " ' "

* Okay, so it's not absolutely necessary to use mm/dd/yyyy format. You
can
use any unambiguous format, such as yyyy-mm-dd or dd mmm yyyy. The point
is,
you can't use dd/mm/yyyy, even if that's what your short date format has
been set to.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



I can get this to work in a totals query but not on a form.

I have this for the control source:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=me.reqdate AND
initials
=me.initials")+1

Do I have the format wrong? I'm looking to return the count value and
then
concatenate the 3 parts of the Ref#.


I want my db to generate our reference # automatically based on input
from
other fields. The number is the date record entered, the users
initials,
and
an incremental number. Ex. 120505GMM02

My form is based on a query and I have the query generating the first
two
components from the date entered in reqdate and the initials entered.
How
can
I get an incremental number generated to go with the rest.

The number should start with 01 for each day and also for each user.
Therefore when GMM is entering his third record on the 5th it should
generate
120505GMM03 even if there were 10 other records entered on the fifth
by
other
users. Each users numbers would start at 01 for each day.

Thanks.
 
D

Douglas J. Steele

Is reqdate in your table a Date/Time field, or simply a Text field
containing a date? Does the field reqdate on your form contain a valid date?

You could try changing the names of the controls on your forms: sometimes
Access gets confused when the name of the control and the name of the field
is the same (even though it chooses to name the controls that way...) I
always rename all of my textboxes so that they start with a txt prefix, so
that my statement would actually be:

=DCount("[incr]","pickupreqdata","[reqdate]=" &
Format(me.txtReqDate,"\#mm\/dd\/yyyy\#") & " AND initials = '" &
me.txtInitials & "'")+1

Also, see whether replace [incr] with * makes any difference (I wouldn't
really expect it to...)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Gary said:
John,

When I place this in the control I get a #NAME? error:

=DCount("[incr]","pickupreqdata","[reqdate]=" &
Format(me.reqdate,"\#mm\/dd\/yyyy\#") & " AND initials = '" & me.initials
&
"'")+1

The only things I changed from your string was the field to count (from
Initials to INCR) and from the form name to the table name.

Gary

John Spencer said:
I think Doug must have been tired. He missed an opening quote mark before
the date format and an ampersand between "initials =" and "me.initials"

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,"\#mm\/dd\/yyyy\#") & " AND initials = '" & me.initials
&
"'")+1


Gary said:
Douglas,

Thanks for your reply.

When I enter your string into the control on the form, I receive this
error:

The expression you entered contains invalid syntax.
You may have entered a comma without a preceding value or identifier.

Thanks.

:

Yes, your format is incorrect.

The values you're checking need to go outside of the quotes.
Additional,
dates must be delimited with # (and in mm/dd/yyyy format, regardless
of
what
your short date format has been set to through Regional Settings)*,
and
strings with quotes.

Try the following:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,
\#mm\/dd\/yyyy\#") & " AND initials = '" me.initials & "'")+1

Note that, exagerated for clarity, that last bit is:

& " AND initials = ' " me.initials & " ' "

* Okay, so it's not absolutely necessary to use mm/dd/yyyy format. You
can
use any unambiguous format, such as yyyy-mm-dd or dd mmm yyyy. The
point
is,
you can't use dd/mm/yyyy, even if that's what your short date format
has
been set to.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



I can get this to work in a totals query but not on a form.

I have this for the control source:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=me.reqdate AND
initials
=me.initials")+1

Do I have the format wrong? I'm looking to return the count value
and
then
concatenate the 3 parts of the Ref#.


I want my db to generate our reference # automatically based on
input
from
other fields. The number is the date record entered, the users
initials,
and
an incremental number. Ex. 120505GMM02

My form is based on a query and I have the query generating the
first
two
components from the date entered in reqdate and the initials
entered.
How
can
I get an incremental number generated to go with the rest.

The number should start with 01 for each day and also for each user.
Therefore when GMM is entering his third record on the 5th it should
generate
120505GMM03 even if there were 10 other records entered on the fifth
by
other
users. Each users numbers would start at 01 for each day.

Thanks.
 
G

Guest

Doug,

It is a date/time format as general date.

I changed the name of the controls to have a txt prefix but to no avail. I
still get the #NAME? error.

This is my current string:

=DCount("[INCR]","tblPURD","[reqdate]=" &
Format(me.txtreqdate,"\#mm\/dd\/yyyy\#") & " AND [initials] = '" &
me.txtinitials & "'")+1

(Changed table name from PickUpReqData to tblPURD

Thanks.

Douglas J. Steele said:
Is reqdate in your table a Date/Time field, or simply a Text field
containing a date? Does the field reqdate on your form contain a valid date?

You could try changing the names of the controls on your forms: sometimes
Access gets confused when the name of the control and the name of the field
is the same (even though it chooses to name the controls that way...) I
always rename all of my textboxes so that they start with a txt prefix, so
that my statement would actually be:

=DCount("[incr]","pickupreqdata","[reqdate]=" &
Format(me.txtReqDate,"\#mm\/dd\/yyyy\#") & " AND initials = '" &
me.txtInitials & "'")+1

Also, see whether replace [incr] with * makes any difference (I wouldn't
really expect it to...)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Gary said:
John,

When I place this in the control I get a #NAME? error:

=DCount("[incr]","pickupreqdata","[reqdate]=" &
Format(me.reqdate,"\#mm\/dd\/yyyy\#") & " AND initials = '" & me.initials
&
"'")+1

The only things I changed from your string was the field to count (from
Initials to INCR) and from the form name to the table name.

Gary

John Spencer said:
I think Doug must have been tired. He missed an opening quote mark before
the date format and an ampersand between "initials =" and "me.initials"

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,"\#mm\/dd\/yyyy\#") & " AND initials = '" & me.initials
&
"'")+1


Douglas,

Thanks for your reply.

When I enter your string into the control on the form, I receive this
error:

The expression you entered contains invalid syntax.
You may have entered a comma without a preceding value or identifier.

Thanks.

:

Yes, your format is incorrect.

The values you're checking need to go outside of the quotes.
Additional,
dates must be delimited with # (and in mm/dd/yyyy format, regardless
of
what
your short date format has been set to through Regional Settings)*,
and
strings with quotes.

Try the following:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,
\#mm\/dd\/yyyy\#") & " AND initials = '" me.initials & "'")+1

Note that, exagerated for clarity, that last bit is:

& " AND initials = ' " me.initials & " ' "

* Okay, so it's not absolutely necessary to use mm/dd/yyyy format. You
can
use any unambiguous format, such as yyyy-mm-dd or dd mmm yyyy. The
point
is,
you can't use dd/mm/yyyy, even if that's what your short date format
has
been set to.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



I can get this to work in a totals query but not on a form.

I have this for the control source:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=me.reqdate AND
initials
=me.initials")+1

Do I have the format wrong? I'm looking to return the count value
and
then
concatenate the 3 parts of the Ref#.


I want my db to generate our reference # automatically based on
input
from
other fields. The number is the date record entered, the users
initials,
and
an incremental number. Ex. 120505GMM02

My form is based on a query and I have the query generating the
first
two
components from the date entered in reqdate and the initials
entered.
How
can
I get an incremental number generated to go with the rest.

The number should start with 01 for each day and also for each user.
Therefore when GMM is entering his third record on the 5th it should
generate
120505GMM03 even if there were 10 other records entered on the fifth
by
other
users. Each users numbers would start at 01 for each day.

Thanks.
 
D

Douglas J. Steele

You're sure that txtregdate and txtinitials have legitimate values in them?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Gary said:
Doug,

It is a date/time format as general date.

I changed the name of the controls to have a txt prefix but to no avail.
I
still get the #NAME? error.

This is my current string:

=DCount("[INCR]","tblPURD","[reqdate]=" &
Format(me.txtreqdate,"\#mm\/dd\/yyyy\#") & " AND [initials] = '" &
me.txtinitials & "'")+1

(Changed table name from PickUpReqData to tblPURD

Thanks.

Douglas J. Steele said:
Is reqdate in your table a Date/Time field, or simply a Text field
containing a date? Does the field reqdate on your form contain a valid
date?

You could try changing the names of the controls on your forms: sometimes
Access gets confused when the name of the control and the name of the
field
is the same (even though it chooses to name the controls that way...) I
always rename all of my textboxes so that they start with a txt prefix,
so
that my statement would actually be:

=DCount("[incr]","pickupreqdata","[reqdate]=" &
Format(me.txtReqDate,"\#mm\/dd\/yyyy\#") & " AND initials = '" &
me.txtInitials & "'")+1

Also, see whether replace [incr] with * makes any difference (I wouldn't
really expect it to...)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Gary said:
John,

When I place this in the control I get a #NAME? error:

=DCount("[incr]","pickupreqdata","[reqdate]=" &
Format(me.reqdate,"\#mm\/dd\/yyyy\#") & " AND initials = '" &
me.initials
&
"'")+1

The only things I changed from your string was the field to count (from
Initials to INCR) and from the form name to the table name.

Gary

:

I think Doug must have been tired. He missed an opening quote mark
before
the date format and an ampersand between "initials =" and
"me.initials"

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,"\#mm\/dd\/yyyy\#") & " AND initials = '" &
me.initials
&
"'")+1


Douglas,

Thanks for your reply.

When I enter your string into the control on the form, I receive
this
error:

The expression you entered contains invalid syntax.
You may have entered a comma without a preceding value or
identifier.

Thanks.

:

Yes, your format is incorrect.

The values you're checking need to go outside of the quotes.
Additional,
dates must be delimited with # (and in mm/dd/yyyy format,
regardless
of
what
your short date format has been set to through Regional Settings)*,
and
strings with quotes.

Try the following:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,
\#mm\/dd\/yyyy\#") & " AND initials = '" me.initials & "'")+1

Note that, exagerated for clarity, that last bit is:

& " AND initials = ' " me.initials & " ' "

* Okay, so it's not absolutely necessary to use mm/dd/yyyy format.
You
can
use any unambiguous format, such as yyyy-mm-dd or dd mmm yyyy. The
point
is,
you can't use dd/mm/yyyy, even if that's what your short date
format
has
been set to.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



I can get this to work in a totals query but not on a form.

I have this for the control source:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=me.reqdate AND
initials
=me.initials")+1

Do I have the format wrong? I'm looking to return the count value
and
then
concatenate the 3 parts of the Ref#.


I want my db to generate our reference # automatically based on
input
from
other fields. The number is the date record entered, the users
initials,
and
an incremental number. Ex. 120505GMM02

My form is based on a query and I have the query generating the
first
two
components from the date entered in reqdate and the initials
entered.
How
can
I get an incremental number generated to go with the rest.

The number should start with 01 for each day and also for each
user.
Therefore when GMM is entering his third record on the 5th it
should
generate
120505GMM03 even if there were 10 other records entered on the
fifth
by
other
users. Each users numbers would start at 01 for each day.

Thanks.
 
G

Guest

Yes.

txtreqdate is general date. When I input it I enter, i.e., 12/12 and the
result displayed 12/12/2005

txtInitials is a list box with four choices bound to the field INITIALs in
table tblPURD. Would that affect the result?

When I run a totals query I am able to get the result. Is there any way to
use the results of that query in the control for that field?

Thanks.

Gary
Douglas J. Steele said:
You're sure that txtregdate and txtinitials have legitimate values in them?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Gary said:
Doug,

It is a date/time format as general date.

I changed the name of the controls to have a txt prefix but to no avail.
I
still get the #NAME? error.

This is my current string:

=DCount("[INCR]","tblPURD","[reqdate]=" &
Format(me.txtreqdate,"\#mm\/dd\/yyyy\#") & " AND [initials] = '" &
me.txtinitials & "'")+1

(Changed table name from PickUpReqData to tblPURD

Thanks.

Douglas J. Steele said:
Is reqdate in your table a Date/Time field, or simply a Text field
containing a date? Does the field reqdate on your form contain a valid
date?

You could try changing the names of the controls on your forms: sometimes
Access gets confused when the name of the control and the name of the
field
is the same (even though it chooses to name the controls that way...) I
always rename all of my textboxes so that they start with a txt prefix,
so
that my statement would actually be:

=DCount("[incr]","pickupreqdata","[reqdate]=" &
Format(me.txtReqDate,"\#mm\/dd\/yyyy\#") & " AND initials = '" &
me.txtInitials & "'")+1

Also, see whether replace [incr] with * makes any difference (I wouldn't
really expect it to...)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



John,

When I place this in the control I get a #NAME? error:

=DCount("[incr]","pickupreqdata","[reqdate]=" &
Format(me.reqdate,"\#mm\/dd\/yyyy\#") & " AND initials = '" &
me.initials
&
"'")+1

The only things I changed from your string was the field to count (from
Initials to INCR) and from the form name to the table name.

Gary

:

I think Doug must have been tired. He missed an opening quote mark
before
the date format and an ampersand between "initials =" and
"me.initials"

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,"\#mm\/dd\/yyyy\#") & " AND initials = '" &
me.initials
&
"'")+1


Douglas,

Thanks for your reply.

When I enter your string into the control on the form, I receive
this
error:

The expression you entered contains invalid syntax.
You may have entered a comma without a preceding value or
identifier.

Thanks.

:

Yes, your format is incorrect.

The values you're checking need to go outside of the quotes.
Additional,
dates must be delimited with # (and in mm/dd/yyyy format,
regardless
of
what
your short date format has been set to through Regional Settings)*,
and
strings with quotes.

Try the following:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,
\#mm\/dd\/yyyy\#") & " AND initials = '" me.initials & "'")+1

Note that, exagerated for clarity, that last bit is:

& " AND initials = ' " me.initials & " ' "

* Okay, so it's not absolutely necessary to use mm/dd/yyyy format.
You
can
use any unambiguous format, such as yyyy-mm-dd or dd mmm yyyy. The
point
is,
you can't use dd/mm/yyyy, even if that's what your short date
format
has
been set to.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



I can get this to work in a totals query but not on a form.

I have this for the control source:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=me.reqdate AND
initials
=me.initials")+1

Do I have the format wrong? I'm looking to return the count value
and
then
concatenate the 3 parts of the Ref#.


I want my db to generate our reference # automatically based on
input
from
other fields. The number is the date record entered, the users
initials,
and
an incremental number. Ex. 120505GMM02

My form is based on a query and I have the query generating the
first
two
components from the date entered in reqdate and the initials
entered.
How
can
I get an incremental number generated to go with the rest.

The number should start with 01 for each day and also for each
user.
Therefore when GMM is entering his third record on the 5th it
should
generate
120505GMM03 even if there were 10 other records entered on the
fifth
by
other
users. Each users numbers would start at 01 for each day.

Thanks.
 
D

Douglas J. Steele

What happens when you type that DCount into the Immediate Window (Ctrl-G)?
Do you get an error, or do you get the correct value?

If you've got a Totals query, you can write a routine to retrieve that value
for you.

For instance, something like the following should work:

Function GetNextValue( _
ReqDt As Date, _
Inits As String _
) As Long

Dim dbCurr As DAO.Database
Dim rstCurr As DAO.Recordset
Dim strSQL As String

strSQL = "SELECT Count(*) As RowCount " _
"FROM tblPURD WHERE " _
"[reqdate]=" & Format(ReqDt,"\#mm\/dd\/yyyy\#") & _
" AND [initials] = '" Inits & "'"
Set dbCurr = CurrentDb()
Set rstCurr = dbCurr.OpenRecordset(strSQL)
GetNextValue = rstCurr!RowCount + 1
rstCurr.Close
Set rstCurr = Nothing
Set dbCurr = Nothing

Exit Function



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Gary said:
Yes.

txtreqdate is general date. When I input it I enter, i.e., 12/12 and the
result displayed 12/12/2005

txtInitials is a list box with four choices bound to the field INITIALs in
table tblPURD. Would that affect the result?

When I run a totals query I am able to get the result. Is there any way
to
use the results of that query in the control for that field?

Thanks.

Gary
Douglas J. Steele said:
You're sure that txtregdate and txtinitials have legitimate values in
them?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Gary said:
Doug,

It is a date/time format as general date.

I changed the name of the controls to have a txt prefix but to no
avail.
I
still get the #NAME? error.

This is my current string:

=DCount("[INCR]","tblPURD","[reqdate]=" &
Format(me.txtreqdate,"\#mm\/dd\/yyyy\#") & " AND [initials] = '" &
me.txtinitials & "'")+1

(Changed table name from PickUpReqData to tblPURD

Thanks.

:

Is reqdate in your table a Date/Time field, or simply a Text field
containing a date? Does the field reqdate on your form contain a valid
date?

You could try changing the names of the controls on your forms:
sometimes
Access gets confused when the name of the control and the name of the
field
is the same (even though it chooses to name the controls that way...)
I
always rename all of my textboxes so that they start with a txt
prefix,
so
that my statement would actually be:

=DCount("[incr]","pickupreqdata","[reqdate]=" &
Format(me.txtReqDate,"\#mm\/dd\/yyyy\#") & " AND initials = '" &
me.txtInitials & "'")+1

Also, see whether replace [incr] with * makes any difference (I
wouldn't
really expect it to...)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



John,

When I place this in the control I get a #NAME? error:

=DCount("[incr]","pickupreqdata","[reqdate]=" &
Format(me.reqdate,"\#mm\/dd\/yyyy\#") & " AND initials = '" &
me.initials
&
"'")+1

The only things I changed from your string was the field to count
(from
Initials to INCR) and from the form name to the table name.

Gary

:

I think Doug must have been tired. He missed an opening quote mark
before
the date format and an ampersand between "initials =" and
"me.initials"

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,"\#mm\/dd\/yyyy\#") & " AND initials = '" &
me.initials
&
"'")+1


Douglas,

Thanks for your reply.

When I enter your string into the control on the form, I receive
this
error:

The expression you entered contains invalid syntax.
You may have entered a comma without a preceding value or
identifier.

Thanks.

:

Yes, your format is incorrect.

The values you're checking need to go outside of the quotes.
Additional,
dates must be delimited with # (and in mm/dd/yyyy format,
regardless
of
what
your short date format has been set to through Regional
Settings)*,
and
strings with quotes.

Try the following:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,
\#mm\/dd\/yyyy\#") & " AND initials = '" me.initials & "'")+1

Note that, exagerated for clarity, that last bit is:

& " AND initials = ' " me.initials & " ' "

* Okay, so it's not absolutely necessary to use mm/dd/yyyy
format.
You
can
use any unambiguous format, such as yyyy-mm-dd or dd mmm yyyy.
The
point
is,
you can't use dd/mm/yyyy, even if that's what your short date
format
has
been set to.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



I can get this to work in a totals query but not on a form.

I have this for the control source:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=me.reqdate
AND
initials
=me.initials")+1

Do I have the format wrong? I'm looking to return the count
value
and
then
concatenate the 3 parts of the Ref#.


I want my db to generate our reference # automatically based
on
input
from
other fields. The number is the date record entered, the users
initials,
and
an incremental number. Ex. 120505GMM02

My form is based on a query and I have the query generating
the
first
two
components from the date entered in reqdate and the initials
entered.
How
can
I get an incremental number generated to go with the rest.

The number should start with 01 for each day and also for each
user.
Therefore when GMM is entering his third record on the 5th it
should
generate
120505GMM03 even if there were 10 other records entered on the
fifth
by
other
users. Each users numbers would start at 01 for each day.

Thanks.
 
G

Guest

From the immediate window I get the following error:

Compile Error:
Expected: Line number or Label or Statement or End of Statement



Douglas J. Steele said:
What happens when you type that DCount into the Immediate Window (Ctrl-G)?
Do you get an error, or do you get the correct value?

If you've got a Totals query, you can write a routine to retrieve that value
for you.

For instance, something like the following should work:

Function GetNextValue( _
ReqDt As Date, _
Inits As String _
) As Long

Dim dbCurr As DAO.Database
Dim rstCurr As DAO.Recordset
Dim strSQL As String

strSQL = "SELECT Count(*) As RowCount " _
"FROM tblPURD WHERE " _
"[reqdate]=" & Format(ReqDt,"\#mm\/dd\/yyyy\#") & _
" AND [initials] = '" Inits & "'"
Set dbCurr = CurrentDb()
Set rstCurr = dbCurr.OpenRecordset(strSQL)
GetNextValue = rstCurr!RowCount + 1
rstCurr.Close
Set rstCurr = Nothing
Set dbCurr = Nothing

Exit Function



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Gary said:
Yes.

txtreqdate is general date. When I input it I enter, i.e., 12/12 and the
result displayed 12/12/2005

txtInitials is a list box with four choices bound to the field INITIALs in
table tblPURD. Would that affect the result?

When I run a totals query I am able to get the result. Is there any way
to
use the results of that query in the control for that field?

Thanks.

Gary
Douglas J. Steele said:
You're sure that txtregdate and txtinitials have legitimate values in
them?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Doug,

It is a date/time format as general date.

I changed the name of the controls to have a txt prefix but to no
avail.
I
still get the #NAME? error.

This is my current string:

=DCount("[INCR]","tblPURD","[reqdate]=" &
Format(me.txtreqdate,"\#mm\/dd\/yyyy\#") & " AND [initials] = '" &
me.txtinitials & "'")+1

(Changed table name from PickUpReqData to tblPURD

Thanks.

:

Is reqdate in your table a Date/Time field, or simply a Text field
containing a date? Does the field reqdate on your form contain a valid
date?

You could try changing the names of the controls on your forms:
sometimes
Access gets confused when the name of the control and the name of the
field
is the same (even though it chooses to name the controls that way...)
I
always rename all of my textboxes so that they start with a txt
prefix,
so
that my statement would actually be:

=DCount("[incr]","pickupreqdata","[reqdate]=" &
Format(me.txtReqDate,"\#mm\/dd\/yyyy\#") & " AND initials = '" &
me.txtInitials & "'")+1

Also, see whether replace [incr] with * makes any difference (I
wouldn't
really expect it to...)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



John,

When I place this in the control I get a #NAME? error:

=DCount("[incr]","pickupreqdata","[reqdate]=" &
Format(me.reqdate,"\#mm\/dd\/yyyy\#") & " AND initials = '" &
me.initials
&
"'")+1

The only things I changed from your string was the field to count
(from
Initials to INCR) and from the form name to the table name.

Gary

:

I think Doug must have been tired. He missed an opening quote mark
before
the date format and an ampersand between "initials =" and
"me.initials"

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,"\#mm\/dd\/yyyy\#") & " AND initials = '" &
me.initials
&
"'")+1


Douglas,

Thanks for your reply.

When I enter your string into the control on the form, I receive
this
error:

The expression you entered contains invalid syntax.
You may have entered a comma without a preceding value or
identifier.

Thanks.

:

Yes, your format is incorrect.

The values you're checking need to go outside of the quotes.
Additional,
dates must be delimited with # (and in mm/dd/yyyy format,
regardless
of
what
your short date format has been set to through Regional
Settings)*,
and
strings with quotes.

Try the following:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,
\#mm\/dd\/yyyy\#") & " AND initials = '" me.initials & "'")+1

Note that, exagerated for clarity, that last bit is:

& " AND initials = ' " me.initials & " ' "

* Okay, so it's not absolutely necessary to use mm/dd/yyyy
format.
You
can
use any unambiguous format, such as yyyy-mm-dd or dd mmm yyyy.
The
point
is,
you can't use dd/mm/yyyy, even if that's what your short date
format
has
been set to.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



I can get this to work in a totals query but not on a form.

I have this for the control source:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=me.reqdate
AND
initials
=me.initials")+1

Do I have the format wrong? I'm looking to return the count
value
and
then
concatenate the 3 parts of the Ref#.


I want my db to generate our reference # automatically based
on
input
from
other fields. The number is the date record entered, the users
initials,
and
an incremental number. Ex. 120505GMM02

My form is based on a query and I have the query generating
the
first
two
components from the date entered in reqdate and the initials
entered.
How
can
I get an incremental number generated to go with the rest.

The number should start with 01 for each day and also for each
user.
Therefore when GMM is entering his third record on the 5th it
should
generate
120505GMM03 even if there were 10 other records entered on the
fifth
by
other
users. Each users numbers would start at 01 for each day.

Thanks.
 
D

Douglas J. Steele

Exactly what did you type in the immediate window?

As long as your form is open, with values in the appropriate text boxes, you
should be typing

?DCount("[INCR]","tblPURD","[reqdate]=" &
Format(me.txtreqdate,"\#mm\/dd\/yyyy\#") & " AND [initials] = '" &
me.txtinitials & "'")+1

and hitting Enter.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Gary said:
From the immediate window I get the following error:

Compile Error:
Expected: Line number or Label or Statement or End of Statement



Douglas J. Steele said:
What happens when you type that DCount into the Immediate Window
(Ctrl-G)?
Do you get an error, or do you get the correct value?

If you've got a Totals query, you can write a routine to retrieve that
value
for you.

For instance, something like the following should work:

Function GetNextValue( _
ReqDt As Date, _
Inits As String _
) As Long

Dim dbCurr As DAO.Database
Dim rstCurr As DAO.Recordset
Dim strSQL As String

strSQL = "SELECT Count(*) As RowCount " _
"FROM tblPURD WHERE " _
"[reqdate]=" & Format(ReqDt,"\#mm\/dd\/yyyy\#") & _
" AND [initials] = '" Inits & "'"
Set dbCurr = CurrentDb()
Set rstCurr = dbCurr.OpenRecordset(strSQL)
GetNextValue = rstCurr!RowCount + 1
rstCurr.Close
Set rstCurr = Nothing
Set dbCurr = Nothing

Exit Function



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Gary said:
Yes.

txtreqdate is general date. When I input it I enter, i.e., 12/12 and
the
result displayed 12/12/2005

txtInitials is a list box with four choices bound to the field INITIALs
in
table tblPURD. Would that affect the result?

When I run a totals query I am able to get the result. Is there any
way
to
use the results of that query in the control for that field?

Thanks.

Gary
:

You're sure that txtregdate and txtinitials have legitimate values in
them?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Doug,

It is a date/time format as general date.

I changed the name of the controls to have a txt prefix but to no
avail.
I
still get the #NAME? error.

This is my current string:

=DCount("[INCR]","tblPURD","[reqdate]=" &
Format(me.txtreqdate,"\#mm\/dd\/yyyy\#") & " AND [initials] = '" &
me.txtinitials & "'")+1

(Changed table name from PickUpReqData to tblPURD

Thanks.

:

Is reqdate in your table a Date/Time field, or simply a Text field
containing a date? Does the field reqdate on your form contain a
valid
date?

You could try changing the names of the controls on your forms:
sometimes
Access gets confused when the name of the control and the name of
the
field
is the same (even though it chooses to name the controls that
way...)
I
always rename all of my textboxes so that they start with a txt
prefix,
so
that my statement would actually be:

=DCount("[incr]","pickupreqdata","[reqdate]=" &
Format(me.txtReqDate,"\#mm\/dd\/yyyy\#") & " AND initials = '" &
me.txtInitials & "'")+1

Also, see whether replace [incr] with * makes any difference (I
wouldn't
really expect it to...)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



John,

When I place this in the control I get a #NAME? error:

=DCount("[incr]","pickupreqdata","[reqdate]=" &
Format(me.reqdate,"\#mm\/dd\/yyyy\#") & " AND initials = '" &
me.initials
&
"'")+1

The only things I changed from your string was the field to count
(from
Initials to INCR) and from the form name to the table name.

Gary

:

I think Doug must have been tired. He missed an opening quote
mark
before
the date format and an ampersand between "initials =" and
"me.initials"

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,"\#mm\/dd\/yyyy\#") & " AND initials = '" &
me.initials
&
"'")+1


Douglas,

Thanks for your reply.

When I enter your string into the control on the form, I
receive
this
error:

The expression you entered contains invalid syntax.
You may have entered a comma without a preceding value or
identifier.

Thanks.

:

Yes, your format is incorrect.

The values you're checking need to go outside of the quotes.
Additional,
dates must be delimited with # (and in mm/dd/yyyy format,
regardless
of
what
your short date format has been set to through Regional
Settings)*,
and
strings with quotes.

Try the following:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,
\#mm\/dd\/yyyy\#") & " AND initials = '" me.initials & "'")+1

Note that, exagerated for clarity, that last bit is:

& " AND initials = ' " me.initials & " ' "

* Okay, so it's not absolutely necessary to use mm/dd/yyyy
format.
You
can
use any unambiguous format, such as yyyy-mm-dd or dd mmm
yyyy.
The
point
is,
you can't use dd/mm/yyyy, even if that's what your short date
format
has
been set to.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



I can get this to work in a totals query but not on a form.

I have this for the control source:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=me.reqdate
AND
initials
=me.initials")+1

Do I have the format wrong? I'm looking to return the count
value
and
then
concatenate the 3 parts of the Ref#.


I want my db to generate our reference # automatically
based
on
input
from
other fields. The number is the date record entered, the
users
initials,
and
an incremental number. Ex. 120505GMM02

My form is based on a query and I have the query generating
the
first
two
components from the date entered in reqdate and the
initials
entered.
How
can
I get an incremental number generated to go with the rest.

The number should start with 01 for each day and also for
each
user.
Therefore when GMM is entering his third record on the 5th
it
should
generate
120505GMM03 even if there were 10 other records entered on
the
fifth
by
other
users. Each users numbers would start at 01 for each day.

Thanks.
 
G

Guest

I had entered it with the = sign.

When I use the ? I receive the error: Compile error - variable not yet
created in this context.

Douglas J. Steele said:
Exactly what did you type in the immediate window?

As long as your form is open, with values in the appropriate text boxes, you
should be typing

?DCount("[INCR]","tblPURD","[reqdate]=" &
Format(me.txtreqdate,"\#mm\/dd\/yyyy\#") & " AND [initials] = '" &
me.txtinitials & "'")+1

and hitting Enter.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Gary said:
From the immediate window I get the following error:

Compile Error:
Expected: Line number or Label or Statement or End of Statement



Douglas J. Steele said:
What happens when you type that DCount into the Immediate Window
(Ctrl-G)?
Do you get an error, or do you get the correct value?

If you've got a Totals query, you can write a routine to retrieve that
value
for you.

For instance, something like the following should work:

Function GetNextValue( _
ReqDt As Date, _
Inits As String _
) As Long

Dim dbCurr As DAO.Database
Dim rstCurr As DAO.Recordset
Dim strSQL As String

strSQL = "SELECT Count(*) As RowCount " _
"FROM tblPURD WHERE " _
"[reqdate]=" & Format(ReqDt,"\#mm\/dd\/yyyy\#") & _
" AND [initials] = '" Inits & "'"
Set dbCurr = CurrentDb()
Set rstCurr = dbCurr.OpenRecordset(strSQL)
GetNextValue = rstCurr!RowCount + 1
rstCurr.Close
Set rstCurr = Nothing
Set dbCurr = Nothing

Exit Function



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Yes.

txtreqdate is general date. When I input it I enter, i.e., 12/12 and
the
result displayed 12/12/2005

txtInitials is a list box with four choices bound to the field INITIALs
in
table tblPURD. Would that affect the result?

When I run a totals query I am able to get the result. Is there any
way
to
use the results of that query in the control for that field?

Thanks.

Gary
:

You're sure that txtregdate and txtinitials have legitimate values in
them?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Doug,

It is a date/time format as general date.

I changed the name of the controls to have a txt prefix but to no
avail.
I
still get the #NAME? error.

This is my current string:

=DCount("[INCR]","tblPURD","[reqdate]=" &
Format(me.txtreqdate,"\#mm\/dd\/yyyy\#") & " AND [initials] = '" &
me.txtinitials & "'")+1

(Changed table name from PickUpReqData to tblPURD

Thanks.

:

Is reqdate in your table a Date/Time field, or simply a Text field
containing a date? Does the field reqdate on your form contain a
valid
date?

You could try changing the names of the controls on your forms:
sometimes
Access gets confused when the name of the control and the name of
the
field
is the same (even though it chooses to name the controls that
way...)
I
always rename all of my textboxes so that they start with a txt
prefix,
so
that my statement would actually be:

=DCount("[incr]","pickupreqdata","[reqdate]=" &
Format(me.txtReqDate,"\#mm\/dd\/yyyy\#") & " AND initials = '" &
me.txtInitials & "'")+1

Also, see whether replace [incr] with * makes any difference (I
wouldn't
really expect it to...)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



John,

When I place this in the control I get a #NAME? error:

=DCount("[incr]","pickupreqdata","[reqdate]=" &
Format(me.reqdate,"\#mm\/dd\/yyyy\#") & " AND initials = '" &
me.initials
&
"'")+1

The only things I changed from your string was the field to count
(from
Initials to INCR) and from the form name to the table name.

Gary

:

I think Doug must have been tired. He missed an opening quote
mark
before
the date format and an ampersand between "initials =" and
"me.initials"

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,"\#mm\/dd\/yyyy\#") & " AND initials = '" &
me.initials
&
"'")+1


Douglas,

Thanks for your reply.

When I enter your string into the control on the form, I
receive
this
error:

The expression you entered contains invalid syntax.
You may have entered a comma without a preceding value or
identifier.

Thanks.

:

Yes, your format is incorrect.

The values you're checking need to go outside of the quotes.
Additional,
dates must be delimited with # (and in mm/dd/yyyy format,
regardless
of
what
your short date format has been set to through Regional
Settings)*,
and
strings with quotes.

Try the following:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,
\#mm\/dd\/yyyy\#") & " AND initials = '" me.initials & "'")+1

Note that, exagerated for clarity, that last bit is:

& " AND initials = ' " me.initials & " ' "

* Okay, so it's not absolutely necessary to use mm/dd/yyyy
format.
You
can
use any unambiguous format, such as yyyy-mm-dd or dd mmm
yyyy.
The
point
is,
you can't use dd/mm/yyyy, even if that's what your short date
format
has
been set to.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



I can get this to work in a totals query but not on a form.

I have this for the control source:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=me.reqdate
AND
initials
=me.initials")+1

Do I have the format wrong? I'm looking to return the count
value
and
then
concatenate the 3 parts of the Ref#.


I want my db to generate our reference # automatically
based
on
input
from
other fields. The number is the date record entered, the
users
initials,
and
an incremental number. Ex. 120505GMM02

My form is based on a query and I have the query generating
the
first
two
components from the date entered in reqdate and the
initials
entered.
How
can
I get an incremental number generated to go with the rest.

The number should start with 01 for each day and also for
each
user.
Therefore when GMM is entering his third record on the 5th
it
 
D

Douglas J. Steele

Darn. Just realized that it probably won't work, as the Immediate Window
won't be able to figure out the references to Me.

I just read your post a little closer. You mention that txtInitials is a
list box. It definitely won't work if the list box is set to multiselect
(even if you're only choosing a single value from the list). In your code,
before your call to DCount, check that the reference to Me.txtInitials is
returning what you think it should.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Gary said:
I had entered it with the = sign.

When I use the ? I receive the error: Compile error - variable not yet
created in this context.

Douglas J. Steele said:
Exactly what did you type in the immediate window?

As long as your form is open, with values in the appropriate text boxes,
you
should be typing

?DCount("[INCR]","tblPURD","[reqdate]=" &
Format(me.txtreqdate,"\#mm\/dd\/yyyy\#") & " AND [initials] = '" &
me.txtinitials & "'")+1

and hitting Enter.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Gary said:
From the immediate window I get the following error:

Compile Error:
Expected: Line number or Label or Statement or End of Statement



:

What happens when you type that DCount into the Immediate Window
(Ctrl-G)?
Do you get an error, or do you get the correct value?

If you've got a Totals query, you can write a routine to retrieve that
value
for you.

For instance, something like the following should work:

Function GetNextValue( _
ReqDt As Date, _
Inits As String _
) As Long

Dim dbCurr As DAO.Database
Dim rstCurr As DAO.Recordset
Dim strSQL As String

strSQL = "SELECT Count(*) As RowCount " _
"FROM tblPURD WHERE " _
"[reqdate]=" & Format(ReqDt,"\#mm\/dd\/yyyy\#") & _
" AND [initials] = '" Inits & "'"
Set dbCurr = CurrentDb()
Set rstCurr = dbCurr.OpenRecordset(strSQL)
GetNextValue = rstCurr!RowCount + 1
rstCurr.Close
Set rstCurr = Nothing
Set dbCurr = Nothing

Exit Function



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Yes.

txtreqdate is general date. When I input it I enter, i.e., 12/12
and
the
result displayed 12/12/2005

txtInitials is a list box with four choices bound to the field
INITIALs
in
table tblPURD. Would that affect the result?

When I run a totals query I am able to get the result. Is there any
way
to
use the results of that query in the control for that field?

Thanks.

Gary
:

You're sure that txtregdate and txtinitials have legitimate values
in
them?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Doug,

It is a date/time format as general date.

I changed the name of the controls to have a txt prefix but to no
avail.
I
still get the #NAME? error.

This is my current string:

=DCount("[INCR]","tblPURD","[reqdate]=" &
Format(me.txtreqdate,"\#mm\/dd\/yyyy\#") & " AND [initials] = '"
&
me.txtinitials & "'")+1

(Changed table name from PickUpReqData to tblPURD

Thanks.

:

Is reqdate in your table a Date/Time field, or simply a Text
field
containing a date? Does the field reqdate on your form contain a
valid
date?

You could try changing the names of the controls on your forms:
sometimes
Access gets confused when the name of the control and the name
of
the
field
is the same (even though it chooses to name the controls that
way...)
I
always rename all of my textboxes so that they start with a txt
prefix,
so
that my statement would actually be:

=DCount("[incr]","pickupreqdata","[reqdate]=" &
Format(me.txtReqDate,"\#mm\/dd\/yyyy\#") & " AND initials = '" &
me.txtInitials & "'")+1

Also, see whether replace [incr] with * makes any difference (I
wouldn't
really expect it to...)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



John,

When I place this in the control I get a #NAME? error:

=DCount("[incr]","pickupreqdata","[reqdate]=" &
Format(me.reqdate,"\#mm\/dd\/yyyy\#") & " AND initials = '" &
me.initials
&
"'")+1

The only things I changed from your string was the field to
count
(from
Initials to INCR) and from the form name to the table name.

Gary

:

I think Doug must have been tired. He missed an opening quote
mark
before
the date format and an ampersand between "initials =" and
"me.initials"

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,"\#mm\/dd\/yyyy\#") & " AND initials = '" &
me.initials
&
"'")+1


Douglas,

Thanks for your reply.

When I enter your string into the control on the form, I
receive
this
error:

The expression you entered contains invalid syntax.
You may have entered a comma without a preceding value or
identifier.

Thanks.

:

Yes, your format is incorrect.

The values you're checking need to go outside of the
quotes.
Additional,
dates must be delimited with # (and in mm/dd/yyyy format,
regardless
of
what
your short date format has been set to through Regional
Settings)*,
and
strings with quotes.

Try the following:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=" &
Format(me.reqdate,
\#mm\/dd\/yyyy\#") & " AND initials = '" me.initials &
"'")+1

Note that, exagerated for clarity, that last bit is:

& " AND initials = ' " me.initials & " ' "

* Okay, so it's not absolutely necessary to use mm/dd/yyyy
format.
You
can
use any unambiguous format, such as yyyy-mm-dd or dd mmm
yyyy.
The
point
is,
you can't use dd/mm/yyyy, even if that's what your short
date
format
has
been set to.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



I can get this to work in a totals query but not on a
form.

I have this for the control source:

=DCount("[initials]","pickupreqdatafrm","[reqdate]=me.reqdate
AND
initials
=me.initials")+1

Do I have the format wrong? I'm looking to return the
count
value
and
then
concatenate the 3 parts of the Ref#.


I want my db to generate our reference # automatically
based
on
input
from
other fields. The number is the date record entered, the
users
initials,
and
an incremental number. Ex. 120505GMM02

My form is based on a query and I have the query
generating
the
first
two
components from the date entered in reqdate and the
initials
entered.
How
can
I get an incremental number generated to go with the
rest.

The number should start with 01 for each day and also
for
each
user.
Therefore when GMM is entering his third record on the
5th
it
 

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