Show Last Record

S

SG

I have a table called tblProducts, withing that table I have a field called
itemcode which is the primary key. The user enters the itemcode for every
product, what I would like to do is be able to display to the user the
previous / last itemcode entered in a list box. Does anyone have any
suggestions?

Many Thanks

S
 
B

Bob Hairgrove

[cross-posting removed]

I have a table called tblProducts, withing that table I have a field called
itemcode which is the primary key. The user enters the itemcode for every
product, what I would like to do is be able to display to the user the
previous / last itemcode entered in a list box. Does anyone have any
suggestions?

Many Thanks

If the itemcode can be sorted, you can use the DMax function to
retrieve its value. What does an itemcode look like?
 
S

SG

The item code can consist of both letters and numbers for example 123TRW123


[cross-posting removed]

I have a table called tblProducts, withing that table I have a field called
itemcode which is the primary key. The user enters the itemcode for every
product, what I would like to do is be able to display to the user the
previous / last itemcode entered in a list box. Does anyone have any
suggestions?

Many Thanks

If the itemcode can be sorted, you can use the DMax function to
retrieve its value. What does an itemcode look like?
 
B

Bob Hairgrove

[cross-posting removed]
If the itemcode can be sorted, you can use the DMax function to
retrieve its value. What does an itemcode look like?

The item code can consist of both letters and numbers for example 123TRW123

If there is a sequence involved, you can create a custom function to
parse it and pass that to the DMax function.

It looks like you have multiple information stored in this field ...
although perhaps useful to management in this format as output in
reports, this kind of "intelligent key" becomes very unwieldy when it
comes to extracting the information it contains, and it can be a major
cause of data inconsistency.

For example, let's assume that you have numeric product id's for
products which are stored in different warehouses. The numeric part of
your item code might identify a part number; the alpha part could
represent the physical storage location. You can imagine how hard it
will be to keep things consistent when the location changes,
especially when the changing data needs to cascade into multiple
related tables. Even worse, the same numbers might refer to different
kinds of items entirely depending on where they are stored.
Unfortunately, many people still design databases this way instead of
normalizing the data strucures.

If there is no sequence which can be constructed from the itemcode, I
suggest adding a DateTime column to the table with a default value of
"Now()" which you could query for the latest entry. This would record
the date and time for new rows (only accurate to one second, but
probably good enough for this unless you have lots of concurrent users
who are adding rows at the same time).

Note that you would need to populate the field somehow for the
existing records...it would remain blank (null) unless you run some
kind of update query to fill it in.
 
J

John Spencer

How do you know what the "Last" itemcode was? Is it a number and you want
the largest Number? Is it an alphanumeric item that you can sort and get
the "last" or "first" in the sortorder as the itemcode you want?

You might be able to use something as simple as the DMAX function

DMax("ItemCode","SomeTableName").
 

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

Similar Threads

Not in list 5
Several Topics in One 1
Calculation Help 2
VB Help 12
How to Clone a record. 3
NO SPAM PLEASE - Stock Value Help 2
Stock Value Reposted NO SPAM REPLIES PLEASE!! 1
Stock Value 1

Top