473,804 Members | 3,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Produce Consecutive Numbers

bwesenberg
17 New Member
I am not sure how to explain this so I will try to the best of my ability.

I need to be able to produce 1000 labels from access that are based on consecutive numbers that Access will produce.

Here are some of the criteria they are looking for:
  • Need to be able to produce labels on demand – generating at least 1,000 labels at a time.
  • The program will know what the last number used was so when they print the next batch of labels it will automatically know.
Here is what I have so far:
  • A table called NumberTable with one field called Number set at a Number Data Type.
  • I have a query called AddNumberQuery that is based off the table. It has the Number field in it and a calculated field which is Number +1.
What I think I need to do is create come kind of Loop to run that query over and over 1000 times and append that data to a table.
My problem is – is that I am not the greatest at code and could use some assistance.

If you have an easier way to do this I would welcome any suggestions. Once I have the data created I can create the report on my own.

Thanks
bwesenberg
Jan 19 '09 #1
2 7020
MindBender77
234 New Member
The easiest way to accomplish this is to create a form with its recordsource linked to your table (NumberTable).

On this form add a single textbox and a command button. Naming the textbox (txt_tempnum) and the command button (cmd_count). Next, change the controlsource of the textbox to the Number field of your table. Finally, add this line of code to the OnClick event of your command button:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmd_count_Click()
  2. Dim counter
  3. Dim MaxNum As Integer
  4.  
  5. If DMax("[Number]", "NumberTable") = 0 Or IsNull(DMax("[Number]", "NumberTable")) = True Then
  6.   MaxNum = 1
  7.  
  8.     For counter = MaxNum To (MaxNum + 1000)
  9.         txt_tempnum = counter
  10.         DoCmd.GoToRecord , , acNewRec
  11.     Next counter
  12.  
  13.     txt_tempnum = Nothing
  14.  
  15. Else
  16.  
  17. MaxNum = DMax("[Number]", "NumberTable")
  18.     For counter = MaxNum To (MaxNum + 1000)
  19.         txt_tempnum = counter
  20.         DoCmd.GoToRecord , , acNewRec
  21.     Next counter
  22.  
  23.     txt_tempnum = Nothing
  24. End If
  25.  
  26. End Sub
  27.  
When you click the command button, it will count/add 1000 to the greatest value in your NumbersTable

HTH,
Bender
Jan 19 '09 #2
NeoPa
32,579 Recognized Expert Moderator MVP
I would start by renaming the field [Number] in your [NumberTable] table to something like [MaxNum]. Using a reserved word is always risky. It's possible to avoid problems with it, but why make life more difficult than it need be?

I would consider then creating a separate table (named [Label] possibly) which would only contain the first thousand records plus the data required for a particular label run (At least a numeric field [LabelNum]. Should be PK). I'll assume for now that this is a single-user process and that it will never be run twice (or more) at the same time.

Ensure that this table is populated with the first 1,000 records (0 < LabelNum <= 1,000). This can be done manually or however you like. It need only be run once ever.

Using the form already described by MindBender (Thx MB), put code behind cmd_Count that will accomplish the following :
  1. Start off by clearing down any previous run of the process :
    Expand|Select|Wrap|Line Numbers
    1. DELETE
    2.  
    3. FROM [Label]
    4.  
    5. WHERE [LabelNum]>1000
  2. Next populate the correct numbers into the [Label] table :
    Expand|Select|Wrap|Line Numbers
    1. INSERT INTO [Label] ([LabelNum])
    2.  
    3. SELECT [LabelNum]+Forms('YourForm').txt_TempNum AS [NewLabelNum]
    4.  
    5. FROM [Label]
    6.  
    7. WHERE [LabelNum]<=1000
  3. Run your report directly off the [Label] table. Ensure you invoke it with a filter where :
    Expand|Select|Wrap|Line Numbers
    1. [LabelNum]>=Forms('YourForm').txt_TempNum
  4. When you're happy the labels have printed off correctly update the value in [NumberTable] (Can be done via the form if preferred). If done directly to the table ensure the form is '.Requery'ed.
  5. Rerun the DELETE query above and return control back to the form.
Jan 20 '09 #3

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

Similar topics

8
3034
by: Adam | last post by:
Hi, I am trying to mark consective numbers in a data set and get a count as to how many consecutive numbers exist in the a given line of data. Here is an example line: 3, 5, 7, 9, 10, 13, 14 The relevant part of the script which currently checks for a
10
6689
by: ChrisD | last post by:
I'm trying extract a count of consecutive numbers, or "unbroken" years in this case, at any particular given time. For example (simplified): CREATE TABLE #Customers ( CustNo INT, YearNo INT, IsCust CHAR(1)
2
4390
by: Iwilfix | last post by:
I am completly new to Access. I need a field to automaticly enter invoice numbers that run consecutive. For example records starting with an invoice # 1276, would autmaticly go to #1277 and #1278 onthe next record. I understand the autonumber, but would like to have a specific starting point thanks in advance
0
446
by: Dennis Ruppert | last post by:
Greetings This should be easy, but I am stuck! I have a table that I import from another program. There are 25 fields, but I only need to use 3 of them for what I need to do. After I import the data, using ODBC, the primary key is multi-field; fieldA, fieldB, fieldC. fieldA is a "Job Number", in text format. fieldB is a number field
9
4458
by: boliches | last post by:
I have a seperate table to generate consecutive numbers. Using "Dmax" to find the largest number to increment . My problem is that I want the number to begin at 1000 at the start of each month, deleteing the previous numbers created in the table. Table : tblNewNum Field: NewNum Januarys Contents of field would read ie. 1000, 1001, 1002, 1003 etc How can I get the first number generated at the start of each month to be 1000?
11
12413
by: xctide | last post by:
This project will give you more experience on nested for loops and user-defined functions. The original project came from an IT company’s programming test where they were asking for the most efficient code to solve one problem. For this assignment we only focus on the correctness of our code and will not consider code efficiency. Background
7
11339
by: Sharkie | last post by:
I need a regular expression which will evaluate to false if number of consecutive characters (non-whitespace) exceeds certain number (10 in this example). For example, I have this function: function test() { var sValue="short unusuallyLongAndWayTooLongString short2"; var regEx=/\S{10,}/; return regEx.test(sValue);
8
3196
by: help2008 | last post by:
Hi I have been doing this working on an assignment for the last week and have stumbled across a part which I cant get my head around. I was hoping that someone could explain what I am missing. I do not expect you to do my work for me. I have completed the rest of the assignment and I am just stuck here (at the very end). Here is my problem. "I have to find out the decimal values of the ratios of consecutive fibonacci numbers." As I said...
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10580
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
10323
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
7621
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
6854
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
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5652
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3821
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2993
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.