Concatonate numbers

T

Tony F

I want to produce a new number by putting together two numbers entered in
seperate fields in a form, e.g. numbers entered = 123 & 456 to produce
123456, then display & print a barcode of that number. Can anyone tell me
if/how this is done?

Many thanks

Tony F
 
J

John W. Vinson

I want to produce a new number by putting together two numbers entered in
seperate fields in a form, e.g. numbers entered = 123 & 456 to produce
123456, then display & print a barcode of that number. Can anyone tell me
if/how this is done?

Many thanks

Tony F

Are these just unbound textboxes on a form, or are the textboxes bound to
fields in a table? If the latter, are the fields text or Number datatype?
 
T

Tony F

Hello Dave
Thanks for the code, but where do I put it? I've tried a couple of places,
e.g. default value for the required cell, but it hasn't worked.

Tony F
 
T

Tony F

Hello John
They are number datatype bound cells.

Also, FYI, I'm using Access 2000

Thanks

Tony F
 
J

John W. Vinson

Hello John
They are number datatype bound cells.

Also, FYI, I'm using Access 2000

In that case you can display the concatenation in a textbox (on a Form or
Report) by setting that textbox's Control Source to

=Cstr([field1]) & Cstr([Field2])

If you'ld like 3 and 25 to be displayed as 003025 (with leading zeros) you can
instead use the Format function:

=Format([field1], "000") & Format([field2], "000")
 
T

Tony F

Thanks John, just what I needed.

For future reference, what would I need to do if I wanted to store the
concatenated number in the table.

Tony F

John W. Vinson said:
Hello John
They are number datatype bound cells.

Also, FYI, I'm using Access 2000

In that case you can display the concatenation in a textbox (on a Form or
Report) by setting that textbox's Control Source to

=Cstr([field1]) & Cstr([Field2])

If you'ld like 3 and 25 to be displayed as 003025 (with leading zeros) you can
instead use the Format function:

=Format([field1], "000") & Format([field2], "000")
 
J

John W. Vinson

Thanks John, just what I needed.

For future reference, what would I need to do if I wanted to store the
concatenated number in the table.

Well, you almost certainaly would NOT want to do so. Storing derived data such
as this in your table accomplishes three things: it wastes disk space; it
wastes time (almost any calculation will be MUCH faster than a disk fetch);
and most importantly, it risks data corruption. If one of the underlying
fields is subsequently edited, you will have data in your table WHICH IS
WRONG, and no automatic way to detect that fact.

Just redo the calculation whenever you need it, either as a calculated field
in a Query or in the control source of a Form or a Report textbox.

If you did have some good reason to do so (e.g. you want to be able to edit
the concatenation separately from the numbers so that they disagree) you'ld
need to "push" the value into a bound textbox in the AfterUpdate event of the
number controls.
 

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