Computing.Net > Forums > Office Software > access finding missing no in series

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

access finding missing no in series

Reply to Message Icon

Name: Eule713
Date: October 27, 2005 at 04:44:20 Pacific
OS: Windows XP SP1
CPU/Ram: P4 640 / 1Gb
Comment:

I am an access user with a fairly limited knowledge of coding hence using queries, reports and to a limited extent functions as provided with access 2003.
How do I go about to find missing numbers in a series of numbers between 600 and 800, i.e. numbers 671 - 677 are missing or number 798 is missing.
Would appreciate if someone could point me in the right direction. Thanks, Wilfried



Sponsored Link
Ads by Google

Response Number 1
Name: StuartS
Date: October 27, 2005 at 17:29:49 Pacific
Reply:

Dim Database As Database
Dim Recordset As Recordset
Dim SQLSelect As String
Dim Recordcount As Long
Dim RecordArray() As Integer
Dim Item As Long
Dim RecordCounter As Long



SQLSelect = "SELECT * from TableName WHERE Number => 6000 and Number =< 8000 Order by Number"

Set Database = OpenDatabase("DataFileName", False, False)
Set Recordset = Database.OpenRecordset(Sele)

Recordset.MoveLast
Recordset.MoveFirst

Recordcount = Recordset.Recordcount
ReDim RecordArray(Recordcount)

Do While Not Recordset.EOF
If RecordCounter <> Recordset("Number") Then
RecordArray(Item) = Recordset("number")
Item = Item + 1
End If
RecordCounter = RecordCounter + 1
Recordset.MoveNext
Loop

Recordset.Close
Database.Close

Some code to get you started. This uses DOA. Using VBA, open your database and using the SQLSelect string, retrieve data with records 600-600 contained in the field name number.

Move to last last record and then back to the first. This ensures that the record count is accurate. This will give you the number of records retrieved from which you can deduce the number of records missing.

Use the number to define an array with the number of elements of missing records.

You then iterate through the records using the variable RecordCounter. When a record is found the does not have a corresponding number it is inserted into the RecordArray and the array counter item is incremented.

At the end of the loop the array should contain all the missing numbers.

The variables are declared as long. If you know for definite that there will never be more than 32,000 records, you can declare them as Integer.

I have not tested this code and it may not work perfectly. But it will give you and idea of what is required.

Stuart


0

Response Number 2
Name: Eule713
Date: October 27, 2005 at 23:15:54 Pacific
Reply:

Hello Stuart,

Thank you very much for your quick response. I will give this one a go over the weekend. I will keep you posted on my progress.

Greetings from downunder, Wilfried


0

Response Number 3
Name: Eule713
Date: November 29, 2005 at 00:29:20 Pacific
Reply:

Hello Stuart,

I have been trying now for some weeks to get your code and/or variations thereof working, but my knowledge of VBA seems to be too little.
There are two basic problems, firstly I can't get the code right without compile error and secondly I am not sure as to how to invoke the code so it runs. That's were I am up to now:

Option Compare Database

Dim MissingNos As Recordset
Dim sqlselect As String
Dim recordcount As Long
Dim recordarray() As Integer
Dim item As Long
Dim recordcounter As Long

Private Sub FindMember_Click()

Set Database = OpenDatabase("d:\data\access\work\FTC - Membership 2005_06 Design.mdb", False, False)

Set MissingNos = Database.OpenRecordset(MissingNos)

MissingNos.MoveLast
MissingNos.MoveFirst

recordcount = MissingNos.recordcount

ReDim recordarray(recordcount)

sqlselect = "SELECT * from members where [Receipt Number] =>600 and [Receipt Number] <= 800 order by [Receipt Number]"

Do While Not MissingNos.EOF

If recordcounter <> MissingNos("Receipt Number") Then recordarray(item) = MissingNos("Receipt Number")
item = item + 1
End If

recordcounter = recordcounter + 1
Recordset.MoveNext
Loop

Recordset.Close
Database.Close

End Sub


Please bear with me for a little longer, I am still on it and hopefully will get somewhere soon. Will keep you posted.

Option Compare Database

Dim MissingNos As Recordset
Dim sqlselect As String
Dim recordcount As Long
Dim recordarray() As Integer
Dim item As Long
Dim recordcounter As Long

Private Sub FindMember_Click()

Set Database = OpenDatabase("d:\data\access\work\FTC - Membership 2005_06 Design.mdb", False, False)

Set MissingNos = Database.OpenRecordset(MissingNos)

MissingNos.MoveLast
MissingNos.MoveFirst

recordcount = MissingNos.recordcount

ReDim recordarray(recordcount)

sqlselect = "SELECT * from members where [Receipt Number] =>600 and [Receipt Number] <= 800 order by [Receipt Number]"

Do While Not MissingNos.EOF

If recordcounter <> MissingNos("Receipt Number") Then recordarray(item) = MissingNos("Receipt Number")
item = item + 1
End If

recordcounter = recordcounter + 1
Recordset.MoveNext
Loop

Recordset.Close
Database.Close

End Sub


0

Response Number 4
Name: Eule713
Date: November 29, 2005 at 00:40:47 Pacific
Reply:

Hello Stuart,

I have been trying now for some weeks to get your code and/or variations thereof working, but my knowledge of VBA seems to be too little.
There are two basic problems, firstly I can't get the code right without compile error and secondly I am not sure as to how to invoke the code so it runs. That's were I am up to now:

Option Compare Database

Dim MissingNos As Recordset
Dim sqlselect As String
Dim recordcount As Long
Dim recordarray() As Integer
Dim item As Long
Dim recordcounter As Long

Private Sub FindMember_Click()

Set Database = OpenDatabase("d:\data\access\work\FTC - Membership 2005_06 Design.mdb", False, False)

Set MissingNos = Database.OpenRecordset(MissingNos)

MissingNos.MoveLast
MissingNos.MoveFirst

recordcount = MissingNos.recordcount

ReDim recordarray(recordcount)

sqlselect = "SELECT * from members where [Receipt Number] =>600 and [Receipt Number] <= 800 order by [Receipt Number]"

Do While Not MissingNos.EOF

If recordcounter <> MissingNos("Receipt Number") Then recordarray(item) = MissingNos("Receipt Number")
item = item + 1
End If

recordcounter = recordcounter + 1
Recordset.MoveNext
Loop

Recordset.Close
Database.Close

End Sub


Please bear with me for a little longer, I am still on it and hopefully will get somewhere soon. Will keep you posted.


Regards, Wilfried


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Office Software Forum Home


Sponsored links

Ads by Google


Results for: access finding missing no in series

cannot find specified file in hyper www.computing.net/answers/office/cannot-find-specified-file-in-hyper/2599.html

Finding closest value in an array www.computing.net/answers/office/finding-closest-value-in-an-array/5528.html

Outlook 2003 - Sent Items lost www.computing.net/answers/office/outlook-2003-sent-items-lost/4710.html