473,769 Members | 7,584 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Find sequential numbers

12 New Member
Thanks to everyone who gave me pointers last time, I got what I needed done, now I have a new one.

We have pulled the invoices from our sales systems into access. The dockets should be sequential, so I want tot find out whic (if any) numbres have been skipped so I can find out why the docket was not invoiced.

I have a table that list lost of information but I'm interested in DockNo from the InvHistory table between certain dates, I can set dates and sort the data but Ilm not sure how check if a number in the sequence is missing short of manually checking.

I have read some threads here (and around the net) while some are similiar to what I want to achieve they used VB Code rather than Access, so any help would be apprciated.
May 31 '07 #1
7 4023
Lysander
344 Recognized Expert Contributor
Thanks to everyone who gave me pointers last time, I got what I needed done, now I have a new one.

We have pulled the invoices from our sales systems into access. The dockets should be sequential, so I want tot find out whic (if any) numbres have been skipped so I can find out why the docket was not invoiced.

I have a table that list lost of information but I'm interested in DockNo from the InvHistory table between certain dates, I can set dates and sort the data but Ilm not sure how check if a number in the sequence is missing short of manually checking.

I have read some threads here (and around the net) while some are similiar to what I want to achieve they used VB Code rather than Access, so any help would be apprciated.
There are two ways you could approach this.

One, create a table that just holds DockNo and populate from 0000 to 9999 or whatever your range of valid docket numbers are, then write a query joining this table with your InvHistory table, showing all DockNo and displaying only those where the InvHistory.Dock No is null. This will list the missing dockets.

Two, write a procedure in code to run through the table and display missing dockets. It would be something like this
Expand|Select|Wrap|Line Numbers
  1. Sub showmissing()
  2. Dim db As Database
  3. Dim rs As Recordset
  4. Dim intDocket As Integer
  5. Dim intX As Integer
  6. Set db = CurrentDb
  7. Set rs = db.OpenRecordset("Select DockNo from InvHistory order by DockNo")
  8. intDocket = rs!DockNo 'This is the first record
  9. intDocket = intDocket + 1 'this should be the next record
  10. While Not rs.EOF
  11.     rs.MoveNext
  12.     If intDocket = rs!DockNo Then
  13.         'we have the correct record
  14.         intDocket = intDocket + 1
  15.     Else
  16.         'Missing 1 or more invoices
  17.         For intX = intDocket To rs!DockNo - 1
  18.             Debug.Print "Missing Invoice No " & intX
  19.             'or write these out to a table
  20.         Next
  21.         intDocket = rs!DockNo + 1
  22.     End If
  23. Wend
  24. rs.Close
  25. Set rs = Nothing
  26. Set db = Nothing
  27. End Sub
  28.  
May 31 '07 #2
Daine
12 New Member
There are two ways you could approach this.

One, create a table that just holds DockNo and populate from 0000 to 9999 or whatever your range of valid docket numbers are, then write a query joining this table with your InvHistory table, showing all DockNo and displaying only those where the InvHistory.Dock No is null. This will list the missing dockets.

Two, write a procedure in code to run through the table and display missing dockets. It would be something like this
Expand|Select|Wrap|Line Numbers
  1. Sub showmissing()
  2. Dim db As Database
  3. Dim rs As Recordset
  4. Dim intDocket As Integer
  5. Dim intX As Integer
  6. Set db = CurrentDb
  7. Set rs = db.OpenRecordset("Select DockNo from InvHistory order by DockNo")
  8. intDocket = rs!DockNo 'This is the first record
  9. intDocket = intDocket + 1 'this should be the next record
  10. While Not rs.EOF
  11.     rs.MoveNext
  12.     If intDocket = rs!DockNo Then
  13.         'we have the correct record
  14.         intDocket = intDocket + 1
  15.     Else
  16.         'Missing 1 or more invoices
  17.         For intX = intDocket To rs!DockNo - 1
  18.             Debug.Print "Missing Invoice No " & intX
  19.             'or write these out to a table
  20.         Next
  21.         intDocket = rs!DockNo + 1
  22.     End If
  23. Wend
  24. rs.Close
  25. Set rs = Nothing
  26. Set db = Nothing
  27. End Sub
  28.  
Thanks for your help, while the first is certainly the eaisiet and one that I considered it would only work for the first location, where as we have several.

The code looks like it would work for me, you have given an option to print to a message box, how do I make it print the missing ones to a table?

OK I tried running the code and got and overflow error on this line:
For intX = intDocket To rs!DocketNo - 1
Jun 1 '07 #3
Daine
12 New Member
OK I tried running the code and got and overflow error on this line:
For intX = intDocket To rs!DocketNo - 1
For some reason I can't edit that post, but I solved that problem by changing the integers to Long.

Still trying to add the data to a table, slowly getting there but learning lots in the meantime.

OK so I got the table part working so thanks for your help on the first part. Now to work out how to speed it up (it doesn't like the 340 000 records lol, I woder why, I don't think I would either)

Set rs = db.OpenRecordse t("Select DockNo from InvHistory order by DockNo")

I'm going to try but incase I need help I'm assuming the part in between the ("") is only a select query in which case I should be able to set dates for it to search between (should be easy) or even get a start and end date input from the user (which is what might take me some time).
Jun 1 '07 #4
Lysander
344 Recognized Expert Contributor
For some reason I can't edit that post, but I solved that problem by changing the integers to Long.

Still trying to add the data to a table, slowly getting there but learning lots in the meantime.

OK so I got the table part working so thanks for your help on the first part. Now to work out how to speed it up (it doesn't like the 340 000 records lol, I woder why, I don't think I would either)

Set rs = db.OpenRecordse t("Select DockNo from InvHistory order by DockNo")

I'm going to try but incase I need help I'm assuming the part in between the ("") is only a select query in which case I should be able to set dates for it to search between (should be easy) or even get a start and end date input from the user (which is what might take me some time).

Yes, the part between the " " is a select query. Design your query in the query builder and then cut and paste the SQL between the quotes.

You asked how to write the data out to a table. Before you open the rs recordset, do this
set rsOutput=db.ope nrecordset("myl ogtable") obviously giving the correct tablename

then instead of debug.print use
rsOutput.addnew
rsOutput!Docket Number=intX
rsOutput.update

and when you close rs, remember to close rsOutput as well.
Jun 1 '07 #5
Daine
12 New Member
Yes, the part between the " " is a select query. Design your query in the query builder and then cut and paste the SQL between the quotes.

You asked how to write the data out to a table. Before you open the rs recordset, do this
set rsOutput=db.ope nrecordset("myl ogtable") obviously giving the correct tablename

then instead of debug.print use
rsOutput.addnew
rsOutput!Docket Number=intX
rsOutput.update

and when you close rs, remember to close rsOutput as well.

Again thanks you have been a big help, I actually got the table working fine though, everything runs as I wanted it. Now I'mm just playing with small inprovements, such as removing the hard coding for dates. In queries if I types where date <=StartDate for example I get a textbox pop up for the input (as the vaule has yet to be defined, is there a way to duplicate this is code as I tried copying the Select query but in the case it stops the code with errors if I try to put teh query in the ("") section, infact it seems to do this anytime I put a where statements in the ("") section.
Jun 3 '07 #6
Lysander
344 Recognized Expert Contributor
Again thanks you have been a big help, I actually got the table working fine though, everything runs as I wanted it. Now I'mm just playing with small inprovements, such as removing the hard coding for dates. In queries if I types where date <=StartDate for example I get a textbox pop up for the input (as the vaule has yet to be defined, is there a way to duplicate this is code as I tried copying the Select query but in the case it stops the code with errors if I try to put teh query in the ("") section, infact it seems to do this anytime I put a where statements in the ("") section.
Glad you got it woking so far.

Not sure how you are running your code, but if from a form, then you could have a combo box (or calendar) to select and hold the start date, ditto for the end date if you have one. Then when you call the code from the form, pass the dates along with it. I tend to use text, and date value, rather than date fields, since sooner or later I hit a pc or server with USA style dates rather than UK ones.

so, you would have called your code, say MatchSales

Now call MatchSales startdate, enddate

and in your code

public sub MatchSales(byva l StartDate as date(or string), byVal Enddate as)

and then build your sql statement. I would build a string, as the sql is getting quite long now.

So, you would have "select blahblah from tbl where startdate>=#21/5/2006#"

Now you can have "select blahblah from tbl where startdate>=date value('" & StartDate & "');"

No more hard coded dates.
Jun 4 '07 #7
Daine
12 New Member
Glad you got it woking so far.

Not sure how you are running your code, but if from a form, then you could have a combo box (or calendar) to select and hold the start date, ditto for the end date if you have one. Then when you call the code from the form, pass the dates along with it. I tend to use text, and date value, rather than date fields, since sooner or later I hit a pc or server with USA style dates rather than UK ones.

so, you would have called your code, say MatchSales

Now call MatchSales startdate, enddate

and in your code

public sub MatchSales(byva l StartDate as date(or string), byVal Enddate as)

and then build your sql statement. I would build a string, as the sql is getting quite long now.

So, you would have "select blahblah from tbl where startdate>=#21/5/2006#"

Now you can have "select blahblah from tbl where startdate>=date value('" & StartDate & "');"

No more hard coded dates.
Again your help is apprecated, I just got back to this little project as other things have taken my time.

I'm never calling the code, I open the database, open the module, hit run. Open the table it prints to and print the table out, and I have my list of missing numbers to chase up before we are audited.

The US/UK date thing isn't a problem for me, our 'dates' are not true dates they are stored as 200706 (yyyymm).

Say I run this query
SELECT InvHist.Period, InvHist.DocketN o, InvHist.PlantNa me, InvHist.Invoice No, InvHist.CustNo, InvHist.ClientN ame, InvHist.Invoice GST
FROM InvHist
WHERE (((InvHist.Peri od)>=sDate And (InvHist.Period )<=eDate))
ORDER BY InvHist.PlantNa me, InvHist.Period, InvHist.DocketN o;

I will get a little popup box (or two) when I run it as the values are undefined, I can simply type 200607 in the first and 200705 in the second, I can't do that from code as I get an error (unexpected amount of parametres passed expected 2).

I suppose I could do a query that prints to a table between the dates (as this would force the boxes) then open that table in the code as is, then open the last table to print- but I'm trying to do everything bar the printing from the code so it is one press open the table and print, I'm not even doing forms as it to run from as it doesn't need to look pretty as long as I get the tables.
Jun 8 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

6
12711
by: Jenn L | last post by:
I have a database that is pre-populated with sequential part numbers. As people reserve the parts I update a flag to show the # is no longer available. Now they want the ability to take out a block of "x" number of sequential part numbers - say for example 5. If my database had the following numbers available: 101 104 105 110
2
2624
by: Ken | last post by:
This is a challenge. Perhaps someone can offer suggestions. I am trying to create a variable, ordernumber, that increases by an increment of 1 every time the variable is accessed. For example: Call up the variable the first time: ordernumber = 1 "Reopen" the webpage, call up the variable a second time: ordernumber = 2, etc.
5
3209
by: Lapchien | last post by:
I have list of numbers in a table (originally from autonumber in a different database) from 1 to 1,000,000. The list is not in sequential order - there are loads of numbers missing. How can I identify what numbers are missing? Thanks, Lap (I'd like to then use this 'missing number list' to use for new records, instead of autonumber - I think I need to use DMax - can someone summarise
14
12048
by: amywolfie | last post by:
Hi All: I know this is simple, but I just can't seem to get there: I need to sort a table by a text field (txtDescription), then assign sequential numbers to the field SEQUENCE in table. Every time a new record is added, the all SEQUENCE #'s must be reset. The re-numbering will be triggered by an EXPORT button.
2
1767
by: Mike Kingscott | last post by:
Hi all, I'd building an app that posts to a web service. One of the things that is required in the soap header is a sequential number appended to a ref, i.e. "IGI1001", "IGI1002", etc. Obviously the first part of the reference ("IGI") stays the same, but I need an incrementing number generated. Now, I was thinking of doing this via a SQL database, but it would be an awful waste as there would only be one table and one stored procedure...
4
25511
by: Mahesh BS | last post by:
Hello, I need to write a query to find out a set of missing number in a given sequence. Eg : a Column in some table has the following data
4
2093
by: Bruce | last post by:
Surely someone has done this before, and I am guessing there is a simple solution that is eluding me. I have a simple report based on a recordset. For each record there is a field (RecNum) that is basically a sequential number from 1 to n. Occasionally there are skips between numbers. I would like to print 'record skipped' for each record missing from the sequence. For example, if there were no records numbered 5 and 6 in a sequence...
6
6969
by: jtidwell | last post by:
I am developing a Work Order Database for my job. I have a combo box with "Contract Numbers" to select from. When you select on any Contract Number I need a new "Work Order Number" to appear. There are 10 different contract numbers so I need 10 different work order numbers (N10001, O100001, etc..) to generate sequential for each new record.
5
3183
by: p3rk3le | last post by:
So, I'm about to do a sequential search on a table (n contents) of random numbers. I have to print the average between the number of comparisons and the contents of the table (n) and the average time for each sequential search. I wrote:
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10214
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9996
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3963
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.