Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autonumbers (range)

Status
Not open for further replies.

mike250

IS-IT--Management
Nov 11, 2002
14
0
0
AU
I need to populate a table column with a range of numbers beginning with 40000000001 through to 400000000500.

So the first record would be 40000000001 and the last record would be 400000000500.

Is there a quick and dirty way to insert each record that sequentially adds a number between this range without me having to type it in for every record?

Thanks in advance!

 
Look in Access help under "Change the starting value of an AutoNumber field (MDB)".

This will provide all the steps necessary to accomplish the task.

Hope this helps.

Glen Appleton

VB.Net student.
 
What I want is this.

We receive a bunch of barcoded customer loyalty cards that are sequential in barcodes. I am building an Avery Label report that also has the same barcodes for affixing to the customers completed form while we hand them their new card.

I want to have an entry form for entering the value of the first barcode on the first sheet, and then the last barcode on the last sheet. It would then automatically populate a table with each and every barcode inbetween that range.

Then my Crystal Report will point to that table and print the avery label sheet based off the values in the table.

Make sense? Can it be done?
 
Mike,

It can be done, but an autonumber is exactly the wrong tool.

The best thing to do is write code to do this.

Jeremy

==
Jeremy Wallace
AlphaBet City Dataworks
Access Databases for Non-Profit Organizations

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
 
Does anyone has code? An example? Cheers!
 
check the FAQ area of this forum and
Forum700
Forum701

you should find plenty of examples!

Leslie


Leslie
 
The following example shows how to append sequential field table using the RunSQL method of the DoCmd object. Make sure you define your barcode field in the table as a Double so it will allow very large numbers.

-----
Code:
Private Sub cmdCreateCodes_Click()

    Dim dblStart As Double, dblEnd As Double, dblIdx As Double
    Dim strSQL As String
    
    ' Convert the textbox values to long integers
    dblStart = CDbl(Me.txtCodeStart.Value)
    dblEnd = CDbl(Me.txtCodeEnd.Value)
    
    ' Data validation
    If dblStart > dblEnd Then
        MsgBox "Input Error: Start value greater than End value.", _
            vbCritical, "Error"
        Exit Sub
    End If
    
    ' Turn off warnings
    DoCmd.SetWarnings False
    
    ' Delete any previous values
    strSQL = "DELETE * FROM Barcodes"
    DoCmd.RunSQL strSQL
    
    ' Add the records to the barcodes table
    For dblIdx = dblStart To dblEnd
        strSQL = "INSERT INTO Barcodes ( Barcode )" & _
                "SELECT " & dblIdx & " AS Barcode;"
        DoCmd.RunSQL strSQL
    Next dblIdx
    
    ' Turn the warnings back on
    DoCmd.SetWarnings True

End Sub
-----

Hope this helps.

Glen Appleton

VB.Net student.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top