Help with creating a model serial number

  • Thread starter mattc66 via AccessMonster.com
  • Start date
M

mattc66 via AccessMonster.com

I have the following code and it works okay, but I need to change how my
serial number is created.

Right now the user inputs the Serial# starting with the first 7 digits as
follows:
K05-123
Then the below code adds a "-" followed by 3 digits starting with 001 until
it reaches the qty entered by the user.

I actual need the user to input the serial# as following (example): K05-123-
020 or in other words they need to enter the starting serial number. From
then on I need the code to assign a sequenctial number from that point until
it reach's the qty input.

Example if they input K05-123-020 and a qty of 5 it would create the
following serial numbers:
K05-123-020
K05-123-021
K05-123-022
K05-123-023
K05-123-024
K05-123-025

Can anyone give me some assitance?
-------------------------------->Current Code-------------------------
Private Sub cmdSeqCreate_Click()

Dim Qty As Integer
Qty = Me.Qty
Dim Serial As String
Serial = Me.Serial
Dim Item As String
Item = Me.Item
Dim UserIntials As String
UserIntials = Me.UserIntials

Dim db As Database

Set db = CurrentDb
Set rs = db.OpenRecordset("tblSeqNumRooms", dbOpenTable)

Do While Qty <> 0

rs.AddNew
rs.Item = Item
rs.Qty = Qty
rs.UserIntials = UserIntials
rs.SerialNum = Serial & "-" & Format(Qty, "000")

rs.Update

Qty = Qty - 1

Loop

rs.Close

End Sub
 
J

Jack Leach

Maybe something like this...


Dim lStartQty As Long 'start qty pulled from current record
Dim lEndQty As Long 'final number
Dim i As Long 'counter

lStartQty = CLng(Right(Me.Serial, 3) + 1
lEndQty = lStartQty + Me.Qty

Do While lEndQty >= lStartQty

rs.Addnew
...
...

lStartQty = lStartQty + 1

Loop
....
....



hth
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
K

KARL DEWEY

Create a table named CountNumber with field CountNUM containing numbers 0
(zero) through your foreseeable maximum.

INSERT INTO tblSeqNumRooms ( Serial )
SELECT [Enter Start of Serial #] & Right("00" & [CountNUM],3) AS Expr2
FROM CountNumber
WHERE (((CountNumber.CountNUM)<=[Enter qunaity of records] And
(CountNumber.CountNUM)>0));
 

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