Custom AutoNumber

R

rpboll

I have a form that has an autonumber. On this form I would like to
include a command button that stamps the word "test" and the value of
the autonumber in a seperate textbox.

The autonumber field is: ID
The TextBox is Text01

When I try this syntax in the onopen event the form it writes "test"
but not the autonumber value.

Me!Text01.value = "test"&[ID]

what do I need to do so it includes the [ID] as well.

Thanks,

rpboll
 
G

Guest

Hi rpboll,

I thought you were trying to use a command button... why have it behind the
on open event?

Anyway, if you use the following syntax it should work:

Me.Text01.value = "test" & me.[ID]

If you are trying to do it with a command button, use the same code in the
On Click event of your command button.

Hope this helps...

Damian.
 
R

rpboll

You're right -- I am using a command button.

I'm adding a new record, which increments the autonumber -- but when
trying to stamp to a textbox it does not include the new autonumber:

Command button:

Command01

DoCmd.GoToRecord , , acNewRec
Me!Stamp.Value = "test" & Me![ID]

Hi rpboll,

I thought you were trying to use a command button... why have it behind the
on open event?

Anyway, if you use the following syntax it should work:

Me.Text01.value = "test" & me.[ID]

If you are trying to do it with a command button, use the same code in the
On Click event of your command button.

Hope this helps...

Damian.



rpboll said:
I have a form that has an autonumber. On this form I would like to
include a command button that stamps the word "test" and the value of
the autonumber in a seperate textbox.
The autonumber field is: ID
The TextBox is Text01
When I try this syntax in the onopen event the form it writes "test"
but not the autonumber value.
Me!Text01.value = "test"&[ID]
what do I need to do so it includes the [ID] as well.

rpboll- Hide quoted text -- Show quoted text -
 
J

John Vinson

You're right -- I am using a command button.

I'm adding a new record, which increments the autonumber -- but when
trying to stamp to a textbox it does not include the new autonumber:

Command button:

Command01

DoCmd.GoToRecord , , acNewRec
Me!Stamp.Value = "test" & Me![ID]

The autonumber doesn't increment until the record has been "dirtied".

I'd suggest a quite different approach. The Stamp field should
certainly NOT exist in your table; it's redundant! Having one field
containing 3122 and another field containing test3122 adds NOTHING of
value to your database.

If you just want to see the text prefix, set the Format property of
the textbox bound to the autonumber field to

"test"#

This won't store the prefix but will display it.

As a rule, autonumbers are best kept "under the hood" and not
displayed to users (with or without prefixes); could you explain why
you feel that you need this?

John W. Vinson[MVP]
 
R

rpboll

I appreciate you pointing that out. I guess I can concatinate the
autonumber with any other field in a query later on. I was just
wandering how to solve the problem so I could combine the results of a
function and an autonumber in one textbox in the entry form.

Thanks.


John said:
You're right -- I am using a command button.

I'm adding a new record, which increments the autonumber -- but when
trying to stamp to a textbox it does not include the new autonumber:

Command button:

Command01

DoCmd.GoToRecord , , acNewRec
Me!Stamp.Value = "test" & Me![ID]

The autonumber doesn't increment until the record has been "dirtied".

I'd suggest a quite different approach. The Stamp field should
certainly NOT exist in your table; it's redundant! Having one field
containing 3122 and another field containing test3122 adds NOTHING of
value to your database.

If you just want to see the text prefix, set the Format property of
the textbox bound to the autonumber field to

"test"#

This won't store the prefix but will display it.

As a rule, autonumbers are best kept "under the hood" and not
displayed to users (with or without prefixes); could you explain why
you feel that you need this?

John W. Vinson[MVP]
 
J

John Vinson

I appreciate you pointing that out. I guess I can concatinate the
autonumber with any other field in a query later on. I was just
wandering how to solve the problem so I could combine the results of a
function and an autonumber in one textbox in the entry form.

That's TWO reasons not to store the field in the table: the autonumber
and the function.

I still don't have a clear idea *why* you want to do this, or for that
matter why you want to display the autonumber value at all, but it's
your database!

John W. Vinson[MVP]
 

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