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!

record gaps 1

Status
Not open for further replies.

scasystems

Programmer
Jan 15, 2003
44
0
0
GB
Got a table with primary key ranging from 1 to 3000
Need to find unused numbers between 1 to 3000.
How?
 
Step 1: Create a table called tblAllNumbers with a field called theNumber make the length long.

Step 2: Write a procedure that will populate tblAllNumbers with the dsired values. This is a simple loop.
Code:
Sub FillAllNumbers()

    Dim strSQL as String
    Dim lngNumber as Long

    For lngNumber = 1 to 3000
       strSQL = "INSERT INTO tblAllNumbers (theNumber) Values (" & lngNumber & ");"
       currentdb.execute strSQL
    next lngNumber
End Sub

Step 3: Create a query with an outer join
Code:
SELECT tblAllNumbers.theNumber, tblYourTable.PK
FROM tblAllNumbers LEFT JOIN tblYourTable ON tblAllNumbers.theNumber = tblYourTable.PK
WHERE (((tblYourTable.PK) Is Null));
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top