473,395 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Find sequential numbers

12
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 3965
Lysander
344 Expert 100+
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.DockNo 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
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.DockNo 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
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.OpenRecordset("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 Expert 100+
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.OpenRecordset("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.openrecordset("mylogtable") obviously giving the correct tablename

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

and when you close rs, remember to close rsOutput as well.
Jun 1 '07 #5
Daine
12
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.openrecordset("mylogtable") obviously giving the correct tablename

then instead of debug.print use
rsOutput.addnew
rsOutput!DocketNumber=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 Expert 100+
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(byval 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>=datevalue('" & StartDate & "');"

No more hard coded dates.
Jun 4 '07 #7
Daine
12
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(byval 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>=datevalue('" & 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.DocketNo, InvHist.PlantName, InvHist.InvoiceNo, InvHist.CustNo, InvHist.ClientName, InvHist.InvoiceGST
FROM InvHist
WHERE (((InvHist.Period)>=sDate And (InvHist.Period)<=eDate))
ORDER BY InvHist.PlantName, InvHist.Period, InvHist.DocketNo;

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
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...
2
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...
5
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...
14
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. ...
2
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. ...
4
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
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...
6
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...
5
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.