Using GetUser() and D(Max) to make a unique number

V

Victoria

Hello,

I am building an order entry database for sales representatives at my
work to be used at conventions to enter customer orders. Since each
database when finished will be installed on each of their computers I
would like to use username on the computer and d(max) function to
create a unique order number to be imprinted on the order report and
stored in the order table. Could somebody please help me. Currently I
have autonumber set as primary key in my orders table which is used to
create all the relationships and the whole order database is pretty
much complete except for this part.

Could someone please help me on this.

Thanks

Victoria
 
A

Al Campagna

Victoria,
I'm glad that you're using the autonumber as the "real" key to relate your data, and
the new (ex. SalesID) for just for "your" use.
Two fields should do it... ex... SalesCount (Long), and UserID(Text)
The DefaultValue for SalesID would be...
= NZ(DMax("[SalesID]", "tblSales")) +1
The DefaultValue for UserID would be...
= [Currentuser]
SalesID would be a calculated unbound field...
= SalesID & UserID
Since you've saved the SalesID and the UserID, there is no need to save the SalesID...
just re-concatenate those values and display it whenever need in any form. query, or
report.
Never save a value can be always be re-derived from other data that you have saved.
Ex. Qty * Price = LineTotal
You would not save Line Total... just recalc it when needed from Price and Qty.
--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."
 
V

Victoria

Victoria,
I'm glad that you're using the autonumber as the "real" key to relate your data, and
the new (ex. SalesID) for just for "your" use.
Two fields should do it... ex... SalesCount (Long), and UserID(Text)
The DefaultValue for SalesID would be...
= NZ(DMax("[SalesID]", "tblSales")) +1
The DefaultValue for UserID would be...
= [Currentuser]
SalesID would be a calculated unbound field...
= SalesID & UserID
Since you've saved the SalesID and the UserID, there is no need to save the SalesID...
just re-concatenate those values and display it whenever need in any form. query, or
report.
Never save a value can be always be re-derived from other data that you have saved.
Ex. Qty * Price = LineTotal
You would not save Line Total... just recalc it when needed from Price and Qty.
--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVPhttp://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."




I am building an order entry database for sales representatives at my
work to be used at conventions to enter customer orders. Since each
database when finished will be installed on each of their computers I
would like to use username on the computer and d(max) function to
create a unique order number to be imprinted on the order report and
stored in the order table. Could somebody please help me. Currently I
have autonumber set as primary key in my orders table which is used to
create all the relationships and the whole order database is pretty
much complete except for this part.
Could someone please help me on this.

Victoria- Hide quoted text -

- Show quoted text -

Hello,
Thanks for your reply. I was actually trying to get the Windows user
id and combined it with Dmax function to create a unique order
number. I found how to pull userid using =Environ("username") in the
control source of an unbound text box but I don't know how to store
that id in the table?

Any ideas?

Thanks,
Victoria
 
A

Al Campagna

Victoria,
Set the control's ControlSource to the UserID (text) field in your table, and make the
DefaultValue for UserID...
=Environ("username")
--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."

Victoria said:
Victoria,
I'm glad that you're using the autonumber as the "real" key to relate your data, and
the new (ex. SalesID) for just for "your" use.
Two fields should do it... ex... SalesCount (Long), and UserID(Text)
The DefaultValue for SalesID would be...
= NZ(DMax("[SalesID]", "tblSales")) +1
The DefaultValue for UserID would be...
= [Currentuser]
SalesID would be a calculated unbound field...
= SalesID & UserID
Since you've saved the SalesID and the UserID, there is no need to save the
SalesID...
just re-concatenate those values and display it whenever need in any form. query, or
report.
Never save a value can be always be re-derived from other data that you have saved.
Ex. Qty * Price = LineTotal
You would not save Line Total... just recalc it when needed from Price and Qty.
--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVPhttp://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."




I am building an order entry database for sales representatives at my
work to be used at conventions to enter customer orders. Since each
database when finished will be installed on each of their computers I
would like to use username on the computer and d(max) function to
create a unique order number to be imprinted on the order report and
stored in the order table. Could somebody please help me. Currently I
have autonumber set as primary key in my orders table which is used to
create all the relationships and the whole order database is pretty
much complete except for this part.
Could someone please help me on this.

Victoria- Hide quoted text -

- Show quoted text -

Hello,
Thanks for your reply. I was actually trying to get the Windows user
id and combined it with Dmax function to create a unique order
number. I found how to pull userid using =Environ("username") in the
control source of an unbound text box but I don't know how to store
that id in the table?

Any ideas?

Thanks,
Victoria
 
V

Victoria

Victoria,
Set the control's ControlSource to the UserID (text) field in your table, and make the
DefaultValue for UserID...
=Environ("username")
--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVPhttp://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."




Victoria,
I'm glad that you're using the autonumber as the "real" key to relate your data, and
the new (ex. SalesID) for just for "your" use.
Two fields should do it... ex... SalesCount (Long), and UserID(Text)
The DefaultValue for SalesID would be...
= NZ(DMax("[SalesID]", "tblSales")) +1
The DefaultValue for UserID would be...
= [Currentuser]
SalesID would be a calculated unbound field...
= SalesID & UserID
Since you've saved the SalesID and the UserID, there is no need to save the
SalesID...
just re-concatenate those values and display it whenever need in any form. query, or
report.
Never save a value can be always be re-derived from other data that you have saved.
Ex. Qty * Price = LineTotal
You would not save Line Total... just recalc it when needed from Price and Qty.
--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVPhttp://home.comcast.net/~cccsolutions
"Find a job that you love, and you'll never work a day in your life."

Hello,
I am building an order entry database for sales representatives at my
work to be used at conventions to enter customer orders. Since each
database when finished will be installed on each of their computers I
would like to use username on the computer and d(max) function to
create a unique order number to be imprinted on the order report and
stored in the order table. Could somebody please help me. Currently I
have autonumber set as primary key in my orders table which is used to
create all the relationships and the whole order database is pretty
much complete except for this part.
Could someone please help me on this.
Thanks
Victoria- Hide quoted text -
- Show quoted text -
Hello,
Thanks for your reply. I was actually trying to get the Windows user
id and combined it with Dmax function to create a unique order
number. I found how to pull userid using =Environ("username") in the
control source of an unbound text box but I don't know how to store
that id in the table?
Any ideas?
Thanks,
Victoria- Hide quoted text -

- Show quoted text -

Hi,
Thank you very much, that worked but I still have a problem with Dmax
function. After reading every newsgroup thread I could find and still
couldn't figure out why my dmax function isn't working. Please help.

I created and Order# field in my Oders table. I set field size to long
integer and index to yes(no duplicates). I set the default value to =
NZ(DMax("[Order#]", "orders")) +1. When I close the table i get the
following error :Unknown function <name> in validation expression or
default value on <name>. (Error 3388). I only do DMax, i stil get the
same error. I then set the default value to 0 and closed the table.

Then I went to my orders form. I created a text box with control
source set to Order# and defaulat value to = NZ(DMax("[Order#]",
"orders")) +1. When I add a new record, i get the following message
The changes you requested to the table were not successful because
they would create duplicate values in the index, primary key, or
relationship. (Error 3022). I cleared the default value field and
closed the box. It seems that having index in the order# in my orders
table be set to yes(no duplicates) creates this error. So I removed
it an set the index to no.

Now it seems to work. However, I thought that unlike the autonumber
which can have gaps if a record was deleted, the max would give me a
sequential number with no gaps. When I add a new order, it gives me
the next number, however, I have undo command button created using
wizard which clears any entries on the current form and deletes the
record. If the udo button is clicked, the order # field is not longer
in sequence. Any ideas as to how I can get sequential order number
even when the user deleted current reocord and decided to start over.

Looking forward to you response.
Victoria.
 
V

Victoria

Victoria,
Set the control's ControlSource to the UserID (text) field in your table, and make the
DefaultValue for UserID...
=Environ("username")
"Find a job that you love, and you'll never work a day in your life."
Victoria,
I'm glad that you're using the autonumber as the "real" key to relate your data, and
the new (ex. SalesID) for just for "your" use.
Two fields should do it... ex... SalesCount (Long), and UserID(Text)
The DefaultValue for SalesID would be...
= NZ(DMax("[SalesID]", "tblSales")) +1
The DefaultValue for UserID would be...
= [Currentuser]
SalesID would be a calculated unbound field...
= SalesID & UserID
Since you've saved the SalesID and the UserID, there is no need to save the
SalesID...
just re-concatenate those values and display it whenever need in any form. query, or
report.
Never save a value can be always be re-derived from other data that you have saved.
Ex. Qty * Price = LineTotal
You would not save Line Total... just recalc it when needed from Price and Qty.
--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVPhttp://home.comcast.net/~cccsolutions
"Find a job that you love, and you'll never work a day in your life."

Hello,
I am building an order entry database for sales representatives at my
work to be used at conventions to enter customer orders. Since each
database when finished will be installed on each of their computers I
would like to use username on the computer and d(max) function to
create a unique order number to be imprinted on the order report and
stored in the order table. Could somebody please help me. Currently I
have autonumber set as primary key in my orders table which is used to
create all the relationships and the whole order database is pretty
much complete except for this part.
Could someone please help me on this.
Thanks
Victoria- Hide quoted text -
- Show quoted text -
Hello,
Thanks for your reply. I was actually trying to get the Windows user
id and combined it with Dmax function to create a unique order
number. I found how to pull userid using =Environ("username") in the
control source of an unbound text box but I don't know how to store
that id in the table?
Any ideas?
Thanks,
Victoria- Hide quoted text -
- Show quoted text -

Hi,
Thank you very much, that worked but I still have a problem with Dmax
function. After reading every newsgroup thread I could find and still
couldn't figure out why my dmax function isn't working. Please help.

I created and Order# field in my Oders table. I set field size to long
integer and index to yes(no duplicates). I set the default value to =
NZ(DMax("[Order#]", "orders")) +1. When I close the table i get the
following error :Unknown function <name> in validation expression or
default value on <name>. (Error 3388). I only do DMax, i stil get the
same error. I then set the default value to 0 and closed the table.

Then I went to my orders form. I created a text box with control
source set to Order# and defaulat value to = NZ(DMax("[Order#]",
"orders")) +1. When I add a new record, i get the following message
The changes you requested to the table were not successful because
they would create duplicate values in the index, primary key, or
relationship. (Error 3022). I cleared the default value field and
closed the box. It seems that having index in the order# in my orders
table be set to yes(no duplicates) creates this error. So I removed
it an set the index to no.

Now it seems to work. However, I thought that unlike the autonumber
which can have gaps if a record was deleted, the max would give me a
sequential number with no gaps. When I add a new order, it gives me
the next number, however, I have undo command button created using
wizard which clears any entries on the current form and deletes the
record. If the udo button is clicked, the order # field is not longer
in sequence. Any ideas as to how I can get sequential order number
even when the user deleted current reocord and decided to start over.

Looking forward to you response.
Victoria.- Hide quoted text -

- Show quoted text -

Hi, Sorry, I would like to add to my previous question. Playing
around with the form, it seems that if i enter infor in the main form,
the counter is 2. If I click undo comman, the order# counter is stil
at 2. Good here. However, if I move to my subform and add some
products and click undo, the order# is now 3. If i then start
reentering the order and click on undo again without entering anything
in the subform, the counter becomes 2. I tried several orders by
entering information in subform and then clicking undo and the couter
goes up by one every time. As soon as I only add information to main
form and click undo, it resets back to the next number in sequence.
Is there a way to have the order# counter reset to the next sequence
even if the user entered a product in subform and then clicked undo?

Thank you,
Victoria
 
A

Al Campagna

Victoria said:
Victoria,
Set the control's ControlSource to the UserID (text) field in your table, and make
the
DefaultValue for UserID...
=Environ("username")
"Find a job that you love, and you'll never work a day in your life."

Victoria,
I'm glad that you're using the autonumber as the "real" key to relate your
data, and
the new (ex. SalesID) for just for "your" use.
Two fields should do it... ex... SalesCount (Long), and UserID(Text)
The DefaultValue for SalesID would be...
= NZ(DMax("[SalesID]", "tblSales")) +1
The DefaultValue for UserID would be...
= [Currentuser]
SalesID would be a calculated unbound field...
= SalesID & UserID
Since you've saved the SalesID and the UserID, there is no need to save the
SalesID...
just re-concatenate those values and display it whenever need in any form. query,
or
report.
Never save a value can be always be re-derived from other data that you have
saved.
Ex. Qty * Price = LineTotal
You would not save Line Total... just recalc it when needed from Price and Qty.
"Find a job that you love, and you'll never work a day in your life."
I am building an order entry database for sales representatives at my
work to be used at conventions to enter customer orders. Since each
database when finished will be installed on each of their computers I
would like to use username on the computer and d(max) function to
create a unique order number to be imprinted on the order report and
stored in the order table. Could somebody please help me. Currently I
have autonumber set as primary key in my orders table which is used to
create all the relationships and the whole order database is pretty
much complete except for this part.
Could someone please help me on this.

Victoria- Hide quoted text -
- Show quoted text -
Hello,
Thanks for your reply. I was actually trying to get the Windows user
id and combined it with Dmax function to create a unique order
number. I found how to pull userid using =Environ("username") in the
control source of an unbound text box but I don't know how to store
that id in the table?
Any ideas?
Thanks,
Victoria- Hide quoted text -
- Show quoted text -

Hi,
Thank you very much, that worked but I still have a problem with Dmax
function. After reading every newsgroup thread I could find and still
couldn't figure out why my dmax function isn't working. Please help.

I created and Order# field in my Oders table. I set field size to long
integer and index to yes(no duplicates). I set the default value to =
NZ(DMax("[Order#]", "orders")) +1. When I close the table i get the
following error :Unknown function <name> in validation expression or
default value on <name>. (Error 3388). I only do DMax, i stil get the
same error. I then set the default value to 0 and closed the table.

Then I went to my orders form. I created a text box with control
source set to Order# and defaulat value to = NZ(DMax("[Order#]",
"orders")) +1. When I add a new record, i get the following message
The changes you requested to the table were not successful because
they would create duplicate values in the index, primary key, or
relationship. (Error 3022). I cleared the default value field and
closed the box. It seems that having index in the order# in my orders
table be set to yes(no duplicates) creates this error. So I removed
it an set the index to no.

Now it seems to work. However, I thought that unlike the autonumber
which can have gaps if a record was deleted, the max would give me a
sequential number with no gaps. When I add a new order, it gives me
the next number, however, I have undo command button created using
wizard which clears any entries on the current form and deletes the
record. If the udo button is clicked, the order # field is not longer
in sequence. Any ideas as to how I can get sequential order number
even when the user deleted current reocord and decided to start over.

Looking forward to you response.
Victoria.- Hide quoted text -

- Show quoted text -

Hi, Sorry, I would like to add to my previous question. Playing
around with the form, it seems that if i enter infor in the main form,
the counter is 2. If I click undo comman, the order# counter is stil
at 2. Good here. However, if I move to my subform and add some
products and click undo, the order# is now 3. If i then start
reentering the order and click on undo again without entering anything
in the subform, the counter becomes 2. I tried several orders by
entering information in subform and then clicking undo and the couter
goes up by one every time. As soon as I only add information to main
form and click undo, it resets back to the next number in sequence.
Is there a way to have the order# counter reset to the next sequence
even if the user entered a product in subform and then clicked undo?

Thank you,
Victoria

Victoria,
Sorry, but you have problems other than a DMax syntax. I can only assume from your
description that your tables have a problem, or some other error that I can't determine...
with certainty.

First, don't use # in a field name. Use something like OrderNo...

Next, the only thing I can think is that you have a problem with the RecordSources for
the Main and Sub forms.
The query (RecordSource) behind the Main form should be just your Orders table. Do not
attempt to relate to your subform table in the Main form's query.
The subform RecordSource should be only your OrderItems table. Same as above, don't
link or join the Main form's table in any way in the subform query.
I can only guess, but it sounds like that... Otherwise, why would the subform OrderNo
change when you set the Main OrderNo to DMax. It should be a slave to the Main form.

--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."
 
V

Victoria

I'm gald you are using quotes around the word "real" ;-)

Jamie.

--

Hi Jamie,

Thanks for your help, the Dmax finally works. I put it in the default
value of the unbound text box.

Victoria
 
Top