Specific "auto numbers" possible?

D

dl

I'm trying to take a simple database I created to track barcode #s and make
it so when a new record is created, a specific barcode number is assigned to
the new record. I have a list of barcode #'s (18 digits, the first 8 are
actual numbers and the following 10 are all zeros). What I'd like to do is
somehow tie this list to the main table so that when a new record is created,
it pulls the next available barcode number and assigns it to this new record.


Any ideas would be greatly appreciated!

Please let me know if I need to explain further.

Thank you!
 
B

BruceM

See here for one method:
http://www.rogersaccesslibrary.com/download3.asp?SampleName=AutonumberProblem.mdb

Roger's example starts at the number 1 (1, 2, 3, etc.). You will need to
adapt the code to accomodate your needs. I suggest that you ignore the ten
zeros when assigning the number. If your first number is to be 00000001
plus the ten zeros, all you need to do is set the number's format to
"00000000". If it is to start with another number you will probably just
enter that number in the first record, then add the code to increment the
number in every record after that. Assuming that this number is in a text
box named txtBarCodeNo on your form, in order to view the finished result
including the zeros at the end, set the control source of an unbound text
box on your form to =[txtBarCodeNo] & "0000000000".
 
G

Guest

I'm trying to take a simple database I created to track barcode #s and make
it so when a new record is created, a specific barcode number is assigned to
the new record. I have a list of barcode #'s (18 digits, the first 8 are
actual numbers and the following 10 are all zeros). What I'd like to do is
somehow tie this list to the main table so that when a new record is created,
it pulls the next available barcode number and assigns it to this new record.

From the Access Help file:

For a new table that contains no records, you can change the starting
value of an AutoNumber field whose NewValues property is set to
Increment to a number other than 1. For a table that contains records,
you can also use this procedure to change the next value assigned in
an AutoNumber field to a new number.

If your original table contains property settings that prevent Null
values in fields, you must temporarily change those properties. These
settings include:
The Required field property set to Yes
The Indexed field property set to Yes (No Duplicates)
A field and/or record ValidationRule property that prevents Null
values in fields
Create a temporary table with just one field: a Number field. Set its
FieldSize property to Long Integer and give it the same name as the
AutoNumber field in the table whose value you want to change.
In Datasheet view enter a value in the Number field of the temporary
table that is one (1) less than the starting value you want for the
AutoNumber field. For example, if you want the AutoNumber field to
start at 100, enter 99 in the Number field.
Create and run an append query to append the temporary table to the
table whose AutoNumber value you want to change.
How?

Create a query that contains the table whose records you want to
append to another table.
How?

In the Database window click Queries under Objects, and then click
New on the Database window toolbar.
In the New Query dialog box, click Design View, and then click OK.
In the Show Table dialog box, click the tab that lists the tables or
queries whose data you want to work with.
Double-click the name of each object you want to add to the query, and
then click Close.
Add fields to the Field row in the design grid and if you want,
specify criteria and a sort order.
To view the query's results, click View on the toolbar.
In query Design view click the arrow next to Query Type on the
toolbar, and then click Append. The Append dialog box appears.
In the Table Name box, enter the name of the table you want to append
records to.
Do one of the following:
If the table is in the currently open database, click Current
Database.

If the table is not in the currently open database, click Another
Database and type the path of the database where the table is stored
or click Browse to locate the database. You can also specify a path to
a Microsoft FoxPro, Paradox, or dBASE database, or a connection string
to an SQL database.

Click OK.
Drag from the field list to the query design grid the fields you want
to append and any fields you want to use for setting criteria.
If all the fields in both tables have the same names, you can just
drag the asterisk (*) to the query design grid. However, if you're
working in a database replica you'll need to add all the fields
instead.

If you have a field with an AutoNumber data type, do one of the
following:
Add AutoNumber values automatically

To have Microsoft Access add AutoNumber values automatically, don't
drag the AutoNumber field to the query design grid when you create the
query.

With this method, Access appends records and automatically inserts
AutoNumber values. The first record appended has a value that is one
larger than the largest entry that was ever entered in the AutoNumber
field (even if the record that contained the largest AutoNumber value
has been deleted).

Use this method if the AutoNumber field in the table you're appending
to is a primary key and the original table and the table you're
appending to contain duplicate AutoNumber values.

Keep the AutoNumber values from the original table

To keep the AutoNumber values from the original table, drag its
AutoNumber field to the query design grid when you create the query.

If the fields you've selected have the same name in both tables,
Microsoft Access automatically fills the matching name in the Append
To row. If the fields in the two tables don't have the same name, in
the Append To row, enter the names of the fields in the table you're
appending to.
In the Criteria cell for the fields that you have dragged to the grid,
type the criteria on which additions will be made.
To preview the records that the query will append, click View on the
toolbar. To return to query Design view, click View on the toolbar
again. Make any changes you want in Design view.
Click Run on the toolbar to add the records.
Delete the temporary table.
Delete the record added by the append query.
If you had to disable property settings in step 1, return them to
their original settings.
When you enter a record in the remaining table, Microsoft Access uses
an AutoNumber field value one (1) greater than the value you entered
in the temporary table.


HTH.

Regards,
Ross
 
B

BruceM

All of this would be fine if you are content with the gaps that almost
ineveitably arise when using autonumber. Autonumber should not be used for
a number the user sees. This is not my view alone, but the almost unanimous
consensus by Access users and professionals with far more expertise than I
have.
 
D

dl

Thank you, everyone.

My only problem is that the 8th digit can never be a zero. The barcode
number must start with 159, followed by two zeros and three regular digits
(i.e. 15900215, but never 15900220) Since this seems to be impossible I've
opted to create the list of specific numbers in excel (weeding out those with
an ending zero) and then importing it as a table. I've then tied them
together with a simple autonumber key.

The challenge will this is that in order for this to work (as far as I know)
I'll have to start with a clean main table. Then in order to integrate the
exsisting table that allowed the barcode to be entered by the user(allowing
the user to still search for/update records); I'm assuming I can simply setup
a query to tie them all together (deleting those barcode numbers already used
in the old table from the newly imported barcode list so there are no
conflicts). Only issue I can think of at this point is the possible
complexity of reporting on the backend.

Any thoughts on simplifying?

Thanks again!
 
B

BruceM

What has led you to conclude that it seems to be impossible? It most
assuredly is not. I don't know if you experimented with the code in the
link I provided, but in general the code works by looking for the highest
value and adding 1. However, if you look for a 9 in the rightmost space you
can just add 2 instead of 1.
One general approach would be to use the form's Current event (untested air
code):

Private Sub Form_Current()

If Me.NewRecord Then
If Right(DMax("BarcodeID","YourTable"),1) = 9 Then
Me.BarcodeID = Format(DMax("BarcodeID","YourTable") + 2,"000")
Else
Me.BarcodeID = Format(DMax("BarcodeID","YourTable") + 1,"000")
End If
End If

Me.txtCompleteNumber = "15900" & BarcodeID & "0000000000"

End Sub

Me.txtCompleteNumber is an unbound text box on the form.

You could also use IIf to accomplish the same thing in the BarcodeID text
box, similar to what Roger outlined in the link I provided.

What happens if you have more than 999 records?

I expect there is some sort of way to loop through the records and use the
unused numbers, but I can't see how to do that. You would need to start a
new thread. If you could just continue from the highest number now in the
table it would be much simpler.

If you need to pull numbers from an existing list you will need to ask
somebody else. I answered the original question, which was about using an
incrementing number. Had I known the additional details that have been
revealed by subsequent postings I would not have attempted a response.
 
T

Tim Ferguson

The barcode
number must start with 159, followed by two zeros and three regular
digits (i.e. 15900215, but never 15900220)

Just set the Format on the text box to

"""15900""000"

This adds the plain text 15900 to the front of a three-digit number. Like
Bruce says, though, this scheme is only good for a thousand rows!

Best wishes


Tim F
 
D

dl

Hi Bruce,
Thank you for the air code, works beautifully. I have close to no
knowledge about VB, but I was able to make your example work.

I have acutally posted this question in the forms section as well, but my
issue now is that when I use your example of: CompleteNumber = "15900" &
BarcodeID & "0000000000" - I had to change it a little to be: ="159" &
[barcodeID] & "0000000000" so that barcodeID was 5 digits long with leading
zeros. However, when I use this string expression in the control source, it
drops the leading zeros and instead of displaying 15900001(10zeros) it
displays 1591(10zeros).

Any idea on how to work around that?

thank you to anyone who can help futher!!
dl
 
B

BruceM

It could be that BarcodeID in your table is defined as a Number field. It
needs to be text. I don't remember if I mentioned that. Other than that,
just tweak the code a little to allow for five digits.

Private Sub Form_Current()

If Me.NewRecord Then
If Right(DMax("BarcodeID","YourTable"),1) = 9 Then
Me.BarcodeID = Format(DMax("BarcodeID","YourTable") +
2,"00000")
Else
Me.BarcodeID = Format(DMax("BarcodeID","YourTable") +
1,"00000")
End If
End If

Me.txtCompleteNumber = "159" & BarcodeID & "0000000000"

End Sub

Why not just put onto your form an umbound text box named txtCompleteNumber?
The code above will take care of populating it.


dl said:
Hi Bruce,
Thank you for the air code, works beautifully. I have close to no
knowledge about VB, but I was able to make your example work.

I have acutally posted this question in the forms section as well, but my
issue now is that when I use your example of: CompleteNumber = "15900" &
BarcodeID & "0000000000" - I had to change it a little to be: ="159" &
[barcodeID] & "0000000000" so that barcodeID was 5 digits long with
leading
zeros. However, when I use this string expression in the control source,
it
drops the leading zeros and instead of displaying 15900001(10zeros) it
displays 1591(10zeros).

Any idea on how to work around that?

thank you to anyone who can help futher!!
dl

BruceM said:
What has led you to conclude that it seems to be impossible? It most
assuredly is not. I don't know if you experimented with the code in the
link I provided, but in general the code works by looking for the highest
value and adding 1. However, if you look for a 9 in the rightmost space
you
can just add 2 instead of 1.
One general approach would be to use the form's Current event (untested
air
code):

Private Sub Form_Current()

If Me.NewRecord Then
If Right(DMax("BarcodeID","YourTable"),1) = 9 Then
Me.BarcodeID = Format(DMax("BarcodeID","YourTable") + 2,"000")
Else
Me.BarcodeID = Format(DMax("BarcodeID","YourTable") +
1,"000")
End If
End If

Me.txtCompleteNumber = "15900" & BarcodeID & "0000000000"

End Sub

Me.txtCompleteNumber is an unbound text box on the form.

You could also use IIf to accomplish the same thing in the BarcodeID text
box, similar to what Roger outlined in the link I provided.

What happens if you have more than 999 records?

I expect there is some sort of way to loop through the records and use
the
unused numbers, but I can't see how to do that. You would need to start
a
new thread. If you could just continue from the highest number now in
the
table it would be much simpler.

If you need to pull numbers from an existing list you will need to ask
somebody else. I answered the original question, which was about using
an
incrementing number. Had I known the additional details that have been
revealed by subsequent postings I would not have attempted a response.
 
D

dl

That was it, when I changed it to txt it then displayed correctly! However,
it's no longer incrementing as new records are created. Any idea why?

BruceM said:
It could be that BarcodeID in your table is defined as a Number field. It
needs to be text. I don't remember if I mentioned that. Other than that,
just tweak the code a little to allow for five digits.

Private Sub Form_Current()

If Me.NewRecord Then
If Right(DMax("BarcodeID","YourTable"),1) = 9 Then
Me.BarcodeID = Format(DMax("BarcodeID","YourTable") +
2,"00000")
Else
Me.BarcodeID = Format(DMax("BarcodeID","YourTable") +
1,"00000")
End If
End If

Me.txtCompleteNumber = "159" & BarcodeID & "0000000000"

End Sub

Why not just put onto your form an umbound text box named txtCompleteNumber?
The code above will take care of populating it.


dl said:
Hi Bruce,
Thank you for the air code, works beautifully. I have close to no
knowledge about VB, but I was able to make your example work.

I have acutally posted this question in the forms section as well, but my
issue now is that when I use your example of: CompleteNumber = "15900" &
BarcodeID & "0000000000" - I had to change it a little to be: ="159" &
[barcodeID] & "0000000000" so that barcodeID was 5 digits long with
leading
zeros. However, when I use this string expression in the control source,
it
drops the leading zeros and instead of displaying 15900001(10zeros) it
displays 1591(10zeros).

Any idea on how to work around that?

thank you to anyone who can help futher!!
dl

BruceM said:
What has led you to conclude that it seems to be impossible? It most
assuredly is not. I don't know if you experimented with the code in the
link I provided, but in general the code works by looking for the highest
value and adding 1. However, if you look for a 9 in the rightmost space
you
can just add 2 instead of 1.
One general approach would be to use the form's Current event (untested
air
code):

Private Sub Form_Current()

If Me.NewRecord Then
If Right(DMax("BarcodeID","YourTable"),1) = 9 Then
Me.BarcodeID = Format(DMax("BarcodeID","YourTable") + 2,"000")
Else
Me.BarcodeID = Format(DMax("BarcodeID","YourTable") +
1,"000")
End If
End If

Me.txtCompleteNumber = "15900" & BarcodeID & "0000000000"

End Sub

Me.txtCompleteNumber is an unbound text box on the form.

You could also use IIf to accomplish the same thing in the BarcodeID text
box, similar to what Roger outlined in the link I provided.

What happens if you have more than 999 records?

I expect there is some sort of way to loop through the records and use
the
unused numbers, but I can't see how to do that. You would need to start
a
new thread. If you could just continue from the highest number now in
the
table it would be much simpler.

If you need to pull numbers from an existing list you will need to ask
somebody else. I answered the original question, which was about using
an
incrementing number. Had I known the additional details that have been
revealed by subsequent postings I would not have attempted a response.

Thank you, everyone.

My only problem is that the 8th digit can never be a zero. The barcode
number must start with 159, followed by two zeros and three regular
digits
(i.e. 15900215, but never 15900220) Since this seems to be impossible
I've
opted to create the list of specific numbers in excel (weeding out
those
with
an ending zero) and then importing it as a table. I've then tied them
together with a simple autonumber key.

The challenge will this is that in order for this to work (as far as I
know)
I'll have to start with a clean main table. Then in order to integrate
the
exsisting table that allowed the barcode to be entered by the
user(allowing
the user to still search for/update records); I'm assuming I can simply
setup
a query to tie them all together (deleting those barcode numbers
already
used
in the old table from the newly imported barcode list so there are no
conflicts). Only issue I can think of at this point is the possible
complexity of reporting on the backend.

Any thoughts on simplifying?

Thanks again!
--
dl


:

All of this would be fine if you are content with the gaps that almost
ineveitably arise when using autonumber. Autonumber should not be
used
for
a number the user sees. This is not my view alone, but the almost
unanimous
consensus by Access users and professionals with far more expertise
than
I
have.

On Tue, 21 Feb 2006 08:04:27 -0800, "dl"

I'm trying to take a simple database I created to track barcode #s
and
make
it so when a new record is created, a specific barcode number is
assigned
to
the new record. I have a list of barcode #'s (18 digits, the first
8
are
actual numbers and the following 10 are all zeros). What I'd like
to
do
is
somehow tie this list to the main table so that when a new record is
created,
it pulls the next available barcode number and assigns it to this
new
record.

From the Access Help file:

For a new table that contains no records, you can change the
starting
value of an AutoNumber field whose NewValues property is set to
Increment to a number other than 1. For a table that contains
records,
you can also use this procedure to change the next value assigned in
an AutoNumber field to a new number.

If your original table contains property settings that prevent Null
values in fields, you must temporarily change those properties.
These
settings include:
The Required field property set to Yes
The Indexed field property set to Yes (No Duplicates)
A field and/or record ValidationRule property that prevents Null
values in fields
Create a temporary table with just one field: a Number field. Set
its
FieldSize property to Long Integer and give it the same name as the
AutoNumber field in the table whose value you want to change.
In Datasheet view enter a value in the Number field of the temporary
table that is one (1) less than the starting value you want for the
AutoNumber field. For example, if you want the AutoNumber field to
start at 100, enter 99 in the Number field.
Create and run an append query to append the temporary table to the
table whose AutoNumber value you want to change.
How?

Create a query that contains the table whose records you want to
append to another table.
How?

In the Database window click Queries under Objects, and then click
New on the Database window toolbar.
In the New Query dialog box, click Design View, and then click OK.
In the Show Table dialog box, click the tab that lists the tables or
queries whose data you want to work with.
Double-click the name of each object you want to add to the query,
and
then click Close.
Add fields to the Field row in the design grid and if you want,
specify criteria and a sort order.
To view the query's results, click View on the toolbar.
In query Design view click the arrow next to Query Type on the
toolbar, and then click Append. The Append dialog box appears.
In the Table Name box, enter the name of the table you want to
append
records to.
Do one of the following:
If the table is in the currently open database, click Current
Database.

If the table is not in the currently open database, click Another
Database and type the path of the database where the table is stored
or click Browse to locate the database. You can also specify a path
to
a Microsoft FoxPro, Paradox, or dBASE database, or a connection
string
to an SQL database.

Click OK.
Drag from the field list to the query design grid the fields you
want
to append and any fields you want to use for setting criteria.
If all the fields in both tables have the same names, you can just
drag the asterisk (*) to the query design grid. However, if you're
working in a database replica you'll need to add all the fields
instead.

If you have a field with an AutoNumber data type, do one of the
following:
Add AutoNumber values automatically

To have Microsoft Access add AutoNumber values automatically, don't
drag the AutoNumber field to the query design grid when you create
the
query.

With this method, Access appends records and automatically inserts
AutoNumber values. The first record appended has a value that is one
larger than the largest entry that was ever entered in the
AutoNumber
field (even if the record that contained the largest AutoNumber
value
has been deleted).

Use this method if the AutoNumber field in the table you're
appending
to is a primary key and the original table and the table you're
appending to contain duplicate AutoNumber values.

Keep the AutoNumber values from the original table

To keep the AutoNumber values from the original table, drag its
AutoNumber field to the query design grid when you create the query.

If the fields you've selected have the same name in both tables,
Microsoft Access automatically fills the matching name in the Append
To row. If the fields in the two tables don't have the same name, in
the Append To row, enter the names of the fields in the table you're
appending to.
In the Criteria cell for the fields that you have dragged to the
grid,
type the criteria on which additions will be made.
To preview the records that the query will append, click View on
the
toolbar. To return to query Design view, click View on the toolbar
again. Make any changes you want in Design view.
Click Run on the toolbar to add the records.
Delete the temporary table.
Delete the record added by the append query.
If you had to disable property settings in step 1, return them to
their original settings.
When you enter a record in the remaining table, Microsoft Access
uses
an AutoNumber field value one (1) greater than the value you entered
in the temporary table.


HTH.

Regards,
Ross
 
D

dl

My appologies, the number not incrementing was being caused by something else
I tried, I deleted this other formatting thing and now it works fine. Sorry
about that.

I'm almost there! Is there a way I can have it continue to increment these
5 digits and always add a zero to the end?
i.e.
001230
001240

thank you so much for all the help!!!

dl said:
That was it, when I changed it to txt it then displayed correctly! However,
it's no longer incrementing as new records are created. Any idea why?

BruceM said:
It could be that BarcodeID in your table is defined as a Number field. It
needs to be text. I don't remember if I mentioned that. Other than that,
just tweak the code a little to allow for five digits.

Private Sub Form_Current()

If Me.NewRecord Then
If Right(DMax("BarcodeID","YourTable"),1) = 9 Then
Me.BarcodeID = Format(DMax("BarcodeID","YourTable") +
2,"00000")
Else
Me.BarcodeID = Format(DMax("BarcodeID","YourTable") +
1,"00000")
End If
End If

Me.txtCompleteNumber = "159" & BarcodeID & "0000000000"

End Sub

Why not just put onto your form an umbound text box named txtCompleteNumber?
The code above will take care of populating it.


dl said:
Hi Bruce,
Thank you for the air code, works beautifully. I have close to no
knowledge about VB, but I was able to make your example work.

I have acutally posted this question in the forms section as well, but my
issue now is that when I use your example of: CompleteNumber = "15900" &
BarcodeID & "0000000000" - I had to change it a little to be: ="159" &
[barcodeID] & "0000000000" so that barcodeID was 5 digits long with
leading
zeros. However, when I use this string expression in the control source,
it
drops the leading zeros and instead of displaying 15900001(10zeros) it
displays 1591(10zeros).

Any idea on how to work around that?

thank you to anyone who can help futher!!
dl

:

What has led you to conclude that it seems to be impossible? It most
assuredly is not. I don't know if you experimented with the code in the
link I provided, but in general the code works by looking for the highest
value and adding 1. However, if you look for a 9 in the rightmost space
you
can just add 2 instead of 1.
One general approach would be to use the form's Current event (untested
air
code):

Private Sub Form_Current()

If Me.NewRecord Then
If Right(DMax("BarcodeID","YourTable"),1) = 9 Then
Me.BarcodeID = Format(DMax("BarcodeID","YourTable") + 2,"000")
Else
Me.BarcodeID = Format(DMax("BarcodeID","YourTable") +
1,"000")
End If
End If

Me.txtCompleteNumber = "15900" & BarcodeID & "0000000000"

End Sub

Me.txtCompleteNumber is an unbound text box on the form.

You could also use IIf to accomplish the same thing in the BarcodeID text
box, similar to what Roger outlined in the link I provided.

What happens if you have more than 999 records?

I expect there is some sort of way to loop through the records and use
the
unused numbers, but I can't see how to do that. You would need to start
a
new thread. If you could just continue from the highest number now in
the
table it would be much simpler.

If you need to pull numbers from an existing list you will need to ask
somebody else. I answered the original question, which was about using
an
incrementing number. Had I known the additional details that have been
revealed by subsequent postings I would not have attempted a response.

Thank you, everyone.

My only problem is that the 8th digit can never be a zero. The barcode
number must start with 159, followed by two zeros and three regular
digits
(i.e. 15900215, but never 15900220) Since this seems to be impossible
I've
opted to create the list of specific numbers in excel (weeding out
those
with
an ending zero) and then importing it as a table. I've then tied them
together with a simple autonumber key.

The challenge will this is that in order for this to work (as far as I
know)
I'll have to start with a clean main table. Then in order to integrate
the
exsisting table that allowed the barcode to be entered by the
user(allowing
the user to still search for/update records); I'm assuming I can simply
setup
a query to tie them all together (deleting those barcode numbers
already
used
in the old table from the newly imported barcode list so there are no
conflicts). Only issue I can think of at this point is the possible
complexity of reporting on the backend.

Any thoughts on simplifying?

Thanks again!
--
dl


:

All of this would be fine if you are content with the gaps that almost
ineveitably arise when using autonumber. Autonumber should not be
used
for
a number the user sees. This is not my view alone, but the almost
unanimous
consensus by Access users and professionals with far more expertise
than
I
have.

On Tue, 21 Feb 2006 08:04:27 -0800, "dl"

I'm trying to take a simple database I created to track barcode #s
and
make
it so when a new record is created, a specific barcode number is
assigned
to
the new record. I have a list of barcode #'s (18 digits, the first
8
are
actual numbers and the following 10 are all zeros). What I'd like
to
do
is
somehow tie this list to the main table so that when a new record is
created,
it pulls the next available barcode number and assigns it to this
new
record.

From the Access Help file:

For a new table that contains no records, you can change the
starting
value of an AutoNumber field whose NewValues property is set to
Increment to a number other than 1. For a table that contains
records,
you can also use this procedure to change the next value assigned in
an AutoNumber field to a new number.

If your original table contains property settings that prevent Null
values in fields, you must temporarily change those properties.
These
settings include:
The Required field property set to Yes
The Indexed field property set to Yes (No Duplicates)
A field and/or record ValidationRule property that prevents Null
values in fields
Create a temporary table with just one field: a Number field. Set
its
FieldSize property to Long Integer and give it the same name as the
AutoNumber field in the table whose value you want to change.
In Datasheet view enter a value in the Number field of the temporary
table that is one (1) less than the starting value you want for the
AutoNumber field. For example, if you want the AutoNumber field to
start at 100, enter 99 in the Number field.
Create and run an append query to append the temporary table to the
table whose AutoNumber value you want to change.
How?

Create a query that contains the table whose records you want to
append to another table.
How?

In the Database window click Queries under Objects, and then click
New on the Database window toolbar.
In the New Query dialog box, click Design View, and then click OK.
In the Show Table dialog box, click the tab that lists the tables or
queries whose data you want to work with.
Double-click the name of each object you want to add to the query,
and
then click Close.
Add fields to the Field row in the design grid and if you want,
specify criteria and a sort order.
To view the query's results, click View on the toolbar.
In query Design view click the arrow next to Query Type on the
toolbar, and then click Append. The Append dialog box appears.
In the Table Name box, enter the name of the table you want to
append
records to.
Do one of the following:
If the table is in the currently open database, click Current
Database.

If the table is not in the currently open database, click Another
Database and type the path of the database where the table is stored
or click Browse to locate the database. You can also specify a path
to
a Microsoft FoxPro, Paradox, or dBASE database, or a connection
string
to an SQL database.

Click OK.
Drag from the field list to the query design grid the fields you
want
to append and any fields you want to use for setting criteria.
If all the fields in both tables have the same names, you can just
drag the asterisk (*) to the query design grid. However, if you're
working in a database replica you'll need to add all the fields
instead.

If you have a field with an AutoNumber data type, do one of the
following:
Add AutoNumber values automatically

To have Microsoft Access add AutoNumber values automatically, don't
drag the AutoNumber field to the query design grid when you create
the
query.

With this method, Access appends records and automatically inserts
AutoNumber values. The first record appended has a value that is one
larger than the largest entry that was ever entered in the
AutoNumber
field (even if the record that contained the largest AutoNumber
value
has been deleted).

Use this method if the AutoNumber field in the table you're
appending
to is a primary key and the original table and the table you're
appending to contain duplicate AutoNumber values.

Keep the AutoNumber values from the original table

To keep the AutoNumber values from the original table, drag its
AutoNumber field to the query design grid when you create the query.

If the fields you've selected have the same name in both tables,
Microsoft Access automatically fills the matching name in the Append
To row. If the fields in the two tables don't have the same name, in
the Append To row, enter the names of the fields in the table you're
appending to.
In the Criteria cell for the fields that you have dragged to the
grid,
type the criteria on which additions will be made.
To preview the records that the query will append, click View on
the
toolbar. To return to query Design view, click View on the toolbar
again. Make any changes you want in Design view.
Click Run on the toolbar to add the records.
Delete the temporary table.
Delete the record added by the append query.
If you had to disable property settings in step 1, return them to
their original settings.
When you enter a record in the remaining table, Microsoft Access
uses
an AutoNumber field value one (1) greater than the value you entered
in the temporary table.


HTH.

Regards,
Ross
 
B

BruceM

See the new string you started in Forms.

dl said:
My appologies, the number not incrementing was being caused by something
else
I tried, I deleted this other formatting thing and now it works fine.
Sorry
about that.

I'm almost there! Is there a way I can have it continue to increment
these
5 digits and always add a zero to the end?
i.e.
001230
001240

thank you so much for all the help!!!

dl said:
That was it, when I changed it to txt it then displayed correctly!
However,
it's no longer incrementing as new records are created. Any idea why?

BruceM said:
It could be that BarcodeID in your table is defined as a Number field.
It
needs to be text. I don't remember if I mentioned that. Other than
that,
just tweak the code a little to allow for five digits.

Private Sub Form_Current()

If Me.NewRecord Then
If Right(DMax("BarcodeID","YourTable"),1) = 9 Then
Me.BarcodeID = Format(DMax("BarcodeID","YourTable") +
2,"00000")
Else
Me.BarcodeID = Format(DMax("BarcodeID","YourTable") +
1,"00000")
End If
End If

Me.txtCompleteNumber = "159" & BarcodeID & "0000000000"

End Sub

Why not just put onto your form an umbound text box named
txtCompleteNumber?
The code above will take care of populating it.


Hi Bruce,
Thank you for the air code, works beautifully. I have close to no
knowledge about VB, but I was able to make your example work.

I have acutally posted this question in the forms section as well,
but my
issue now is that when I use your example of: CompleteNumber =
"15900" &
BarcodeID & "0000000000" - I had to change it a little to be: ="159"
&
[barcodeID] & "0000000000" so that barcodeID was 5 digits long with
leading
zeros. However, when I use this string expression in the control
source,
it
drops the leading zeros and instead of displaying 15900001(10zeros)
it
displays 1591(10zeros).

Any idea on how to work around that?

thank you to anyone who can help futher!!
dl

:

What has led you to conclude that it seems to be impossible? It
most
assuredly is not. I don't know if you experimented with the code in
the
link I provided, but in general the code works by looking for the
highest
value and adding 1. However, if you look for a 9 in the rightmost
space
you
can just add 2 instead of 1.
One general approach would be to use the form's Current event
(untested
air
code):

Private Sub Form_Current()

If Me.NewRecord Then
If Right(DMax("BarcodeID","YourTable"),1) = 9 Then
Me.BarcodeID = Format(DMax("BarcodeID","YourTable") +
2,"000")
Else
Me.BarcodeID = Format(DMax("BarcodeID","YourTable") +
1,"000")
End If
End If

Me.txtCompleteNumber = "15900" & BarcodeID & "0000000000"

End Sub

Me.txtCompleteNumber is an unbound text box on the form.

You could also use IIf to accomplish the same thing in the BarcodeID
text
box, similar to what Roger outlined in the link I provided.

What happens if you have more than 999 records?

I expect there is some sort of way to loop through the records and
use
the
unused numbers, but I can't see how to do that. You would need to
start
a
new thread. If you could just continue from the highest number now
in
the
table it would be much simpler.

If you need to pull numbers from an existing list you will need to
ask
somebody else. I answered the original question, which was about
using
an
incrementing number. Had I known the additional details that have
been
revealed by subsequent postings I would not have attempted a
response.

Thank you, everyone.

My only problem is that the 8th digit can never be a zero. The
barcode
number must start with 159, followed by two zeros and three
regular
digits
(i.e. 15900215, but never 15900220) Since this seems to be
impossible
I've
opted to create the list of specific numbers in excel (weeding out
those
with
an ending zero) and then importing it as a table. I've then tied
them
together with a simple autonumber key.

The challenge will this is that in order for this to work (as far
as I
know)
I'll have to start with a clean main table. Then in order to
integrate
the
exsisting table that allowed the barcode to be entered by the
user(allowing
the user to still search for/update records); I'm assuming I can
simply
setup
a query to tie them all together (deleting those barcode numbers
already
used
in the old table from the newly imported barcode list so there are
no
conflicts). Only issue I can think of at this point is the
possible
complexity of reporting on the backend.

Any thoughts on simplifying?

Thanks again!
--
dl


:

All of this would be fine if you are content with the gaps that
almost
ineveitably arise when using autonumber. Autonumber should not
be
used
for
a number the user sees. This is not my view alone, but the
almost
unanimous
consensus by Access users and professionals with far more
expertise
than
I
have.

On Tue, 21 Feb 2006 08:04:27 -0800, "dl"

I'm trying to take a simple database I created to track barcode
#s
and
make
it so when a new record is created, a specific barcode number
is
assigned
to
the new record. I have a list of barcode #'s (18 digits, the
first
8
are
actual numbers and the following 10 are all zeros). What I'd
like
to
do
is
somehow tie this list to the main table so that when a new
record is
created,
it pulls the next available barcode number and assigns it to
this
new
record.

From the Access Help file:

For a new table that contains no records, you can change the
starting
value of an AutoNumber field whose NewValues property is set to
Increment to a number other than 1. For a table that contains
records,
you can also use this procedure to change the next value
assigned in
an AutoNumber field to a new number.

If your original table contains property settings that prevent
Null
values in fields, you must temporarily change those properties.
These
settings include:
The Required field property set to Yes
The Indexed field property set to Yes (No Duplicates)
A field and/or record ValidationRule property that prevents
Null
values in fields
Create a temporary table with just one field: a Number field.
Set
its
FieldSize property to Long Integer and give it the same name as
the
AutoNumber field in the table whose value you want to change.
In Datasheet view enter a value in the Number field of the
temporary
table that is one (1) less than the starting value you want for
the
AutoNumber field. For example, if you want the AutoNumber field
to
start at 100, enter 99 in the Number field.
Create and run an append query to append the temporary table to
the
table whose AutoNumber value you want to change.
How?

Create a query that contains the table whose records you want
to
append to another table.
How?

In the Database window click Queries under Objects, and then
click
New on the Database window toolbar.
In the New Query dialog box, click Design View, and then click
OK.
In the Show Table dialog box, click the tab that lists the
tables or
queries whose data you want to work with.
Double-click the name of each object you want to add to the
query,
and
then click Close.
Add fields to the Field row in the design grid and if you want,
specify criteria and a sort order.
To view the query's results, click View on the toolbar.
In query Design view click the arrow next to Query Type on the
toolbar, and then click Append. The Append dialog box appears.
In the Table Name box, enter the name of the table you want to
append
records to.
Do one of the following:
If the table is in the currently open database, click Current
Database.

If the table is not in the currently open database, click
Another
Database and type the path of the database where the table is
stored
or click Browse to locate the database. You can also specify a
path
to
a Microsoft FoxPro, Paradox, or dBASE database, or a connection
string
to an SQL database.

Click OK.
Drag from the field list to the query design grid the fields
you
want
to append and any fields you want to use for setting criteria.
If all the fields in both tables have the same names, you can
just
drag the asterisk (*) to the query design grid. However, if
you're
working in a database replica you'll need to add all the fields
instead.

If you have a field with an AutoNumber data type, do one of the
following:
Add AutoNumber values automatically

To have Microsoft Access add AutoNumber values automatically,
don't
drag the AutoNumber field to the query design grid when you
create
the
query.

With this method, Access appends records and automatically
inserts
AutoNumber values. The first record appended has a value that
is one
larger than the largest entry that was ever entered in the
AutoNumber
field (even if the record that contained the largest AutoNumber
value
has been deleted).

Use this method if the AutoNumber field in the table you're
appending
to is a primary key and the original table and the table you're
appending to contain duplicate AutoNumber values.

Keep the AutoNumber values from the original table

To keep the AutoNumber values from the original table, drag its
AutoNumber field to the query design grid when you create the
query.

If the fields you've selected have the same name in both
tables,
Microsoft Access automatically fills the matching name in the
Append
To row. If the fields in the two tables don't have the same
name, in
the Append To row, enter the names of the fields in the table
you're
appending to.
In the Criteria cell for the fields that you have dragged to
the
grid,
type the criteria on which additions will be made.
To preview the records that the query will append, click View
on
the
toolbar. To return to query Design view, click View on the
toolbar
again. Make any changes you want in Design view.
Click Run on the toolbar to add the records.
Delete the temporary table.
Delete the record added by the append query.
If you had to disable property settings in step 1, return them
to
their original settings.
When you enter a record in the remaining table, Microsoft
Access
uses
an AutoNumber field value one (1) greater than the value you
entered
in the temporary table.


HTH.

Regards,
Ross
 

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