473,394 Members | 1,703 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,394 software developers and data experts.

Sequential Invoice Number Multiple Tables

72 64KB
Hi,
I have 3 tables from which 3 different forms create 3 different types of invoices. There are only 2 common fields to all tables(customer, employees).
I would like to add a sequential Invoice number so that no matter what form is used, the invoice number always goes up by 1. The forms create a new record using an insert query.
Would I have to create a fourth table that contains a PK field so that I can use the Dmax+1?

Thanks
Apr 1 '19 #1
12 2406
NeoPa
32,556 Expert Mod 16PB
Sounds like an overly-complicated setup but I don't know the situation it has to match.

Are you saying you're storing the invoices in these three separate tables? If so you'll find life difficult. There are nearly always ways around bad design but the worse the design the more you'll need to use them and the more fragile will be your project.

If you really, really need to create a sequential number between three different tables then it can be done. I could help you with it if I had some reliable information as to exactly what it is you're talking about. You will need to access all three tables and you'll need to take advantage of the format of any invoice numbers stored within. As I have no such knowledge from your question that's as far as I can go at this point.

Please remember in future questions that everyone saves time and energy if you include all relevant information in your original question.
Apr 1 '19 #2
Neruda
72 64KB
Hi,
I am storing Invoices in 3 different tables, yes.
I would go with your intuition that it might be a case of bad design. My end goal is to have this sequential invoice number across 3 tables, I thought about having just one but could not find a way. The tables have mostly unrelated fields.
I have attached a screenshot. They all create a sale receipt using different forms.
I suppose when it comes to retrieve record from a specific date I would have to use a union query from 3 tables?
I might abandon the idea if it gets too messy and have their own Invoice number, maybe with a prefix to distinguish them.

Thanks

Attached Images
File Type: jpg Capture.jpg (44.1 KB, 653 views)
Apr 6 '19 #3
NeoPa
32,556 Expert Mod 16PB
Forget intuition for this (Not generally. It's very important.) as this comes from experience.

Looking at your table designs informs me that you should avoid multiple problems by merging your tables together into a single one. An extra type field would determine which type of invoice it is and any fields that are unused for that type can simply be left as Nulls. The work to create a PK value, even assuming you couldn't use AutoNumber, would be much simpler, as would much more of the work surrounding any work with your invoices. This looks like a no-brainer.
Apr 7 '19 #4
Neruda
72 64KB
Hi,
when you say an extra type field do you mean just a field (in each table)with say 1 as default value for one table, 2 for the second and 3 for the third so as to distinguish them?

Will I be able to use an union query from 3 tables to pull records from a particular day (using same number of fields)?

I read about dmax+1, should I bother in this case?

Thanks
Apr 7 '19 #5
NeoPa
32,556 Expert Mod 16PB
If you were to use three separate tables then the type field wouldn't be necessary, but if you used a single table, with the type field just as you describe it, then everything would work more smoothly. You wouldn't even need to worry about UNION queries (which by the way in Jet or ACE SQL are necessarily non-updatable).

To see or process the invoices from any of the particular states, for which previously you would have a separate table, you simply filter using that [Type] field using whichever value matches that type.
Apr 7 '19 #6
NeoPa
32,556 Expert Mod 16PB
Neruda:
I read about dmax+1, should I bother in this case?
Let's get to where we know what you're actually working with before we answer that one. Hopefully it won't be necessary but it will depend on understanding how you're storing your data. Information we don't yet have.
Apr 7 '19 #7
Neruda
72 64KB
to have just one larger table is something I had not considered! because of all the null entry. I thought leaving many nulls would not be a good idea. But I suppose it would simplify things a lot. It doesn't really matter does it?
I think i'll do just that, each record will have a type field in one larger table.
Apr 7 '19 #8
NeoPa
32,556 Expert Mod 16PB
That's part of the question Neruda. How about your ID field. Is it a simple number or is it a formatted string that people sometimes like in order to show some information?

If it's a simple number then an AutoNumber field will work perfectly well and Access will handle setting that for you automatically. If it's the latter then you may need to use the DMax() approach, but we'll need to know how it's formatted if you'd like us to help with that.
Apr 7 '19 #9
Neruda
72 64KB
Hi,
this id field is a number with a two letter prefix. Ideally I would like to have the ability to change the prefix. I could store the prefix in a table I already have, i suppose.

About the forms:
form 1 uses an insert query for enterering data
forms 2 & 3 use a form and records can be aborted

there will never be more than person using the app.

The Invoice ID would look like WE0000001 or KW0000001 and should not miss numbers. I would like the prefix to be changable from a standard form, without opening the app.

Thanks
Apr 14 '19 #10
NeoPa
32,556 Expert Mod 16PB
You still give very little clue as to what you're really talking about. If you want multiple possible prefixes then that should surely be included in your question. It's no fun running around trying to guess what it is you want after asking you to explain it properly.

Also, talking of forms makes absolutely no sense unless you explain why. Forms don't contain data and your question seems to imply you get the information from a form. That simply doesn't make any sense.

What is it you're trying to achieve? Are there different two-letter codes as prefixes? If there are then does the numeric part depend on which is used or is it sequential regardless which code is used? How should the actual two-letter code be determined?
Apr 18 '19 #11
Neruda
72 64KB
I would like to have a sequential Invoice number field in a table (in the title).
The Invoice Number should look like this:
a 2 letter prefix + 7 sequential digits (eg WE0000001)
The user will determine which prefix he wants to use. Can be any 2 letters. The user will edit the prefix using a form. The default value is DF0000001. The numeric part increases regardless of the letters chosen .
Apr 19 '19 #12
NeoPa
32,556 Expert Mod 16PB
OK. It seems like we're close enough to a clear question to put out some help here that will actually help. Before we start I'll explain the references so you can match them to your own situation.
My suggestions will assume you have an unbound Control on the current Form (The one the code will be running from.) called [cboPrefix], which will hold the two-letter prefix. Also that the same Form has a TextBox Control called [txtInvoiceNo] that will be used to represent the field [InvoiceNo] and that this will be set whenever [cboPrefix] is updated. It will also assume that the table we're dealing with is called [tblInvoice].

There are two ways to handle this :
  1. This one works with an Access table but, due to an AutoNumber in ODBC-linked tables being created only once the record has been created, not with other types. This solution relies on a separate field (We'll call it [AutoNo]) in [tblInvoice] being set as an AutoNumber. Another caveat is that it is possible in this scenario to create gaps in the sequence by starting to create a record but never saving it. It is always possible to create gaps in any type of system by deleting records from earlier in the sequence after subsequent ones have already been created, but this can be avoided if you disallow such deletions. So, this option should only be taken if you don't care unduly about gaps.

    On to the solution itself. We will need an extra TextBox bound to [AutoNo] which we'll call [txtAutoNo]. The code would be something like :
    Expand|Select|Wrap|Line Numbers
    1. Private Sub cboPrefix_AfterUpdate()
    2.     With Me
    3.         .txtInvoiceNo.DefaultValue = "='" & .cboPrefix _
    4.                                    & Format(.AutoNo, "0000000") & "'"
    5.     End With
    6. End Sub
    This won't, in itself, cause the new number to be used up, but if any changes are made to the record then the new number is used up and unavailable for future use even if the record isn't saved.
  2. This is a safer approach, although obviously a little more complex. Even with this one though, gaps can be created in the sequence number if you delete records after subsequent records have been created. If that's important then don't allow any such deletions. You can have some form of Deleted indicator that means it will be ignored by the rest of the system even though it remains in the table.

    This approach relies on scanning the table for existing values and using the one with the highest numerical value to build your next one from.
    Expand|Select|Wrap|Line Numbers
    1. Private Sub cboPrefix_AfterUpdate()
    2.     Dim lngSeq As Long
    3.     Dim strDefaultVal As String
    4.  
    5.     With Me
    6.         lngSeq = Nz(DMax(Expr:="Val(Mid([InvoiceNo],3,99))" _
    7.                        , Domain:="[tblInvoice]"), 0) + 1
    8.         strDefaultVal = Replace("='%P%N'", "%N", Format(lngSeq, "0000000"))
    9.         strDefaultVal = Replace(strDefaultVal, "%P", .cboPrefix)
    10.         .txtInvoiceNo.DefaultValue = strDefaultVal
    11.     End With
    12. End Sub
Neither solution handles numbers extending beyond the seven digits. In both cases the resultant string would include the full extended number.
Apr 20 '19 #13

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

Similar topics

2
by: Sami | last post by:
Could someone explain clearly how to go about doing this? I have tried setting up the structure on numerous occasions, but it never seems to work. Could someone please help me out? Thanks!
3
by: svdh2 | last post by:
I have been looking at a problem the entire week in access, I have still not been able to find a solution. Hope that you could maybe tell where to look Concerns the link between Access and Word....
11
by: dskillingstad | last post by:
I've been struggling with this problem for some time and have tried multiple solutions with no luck. Let me start with, I'm a novice at Access and I'm not looking for someones help to design my...
0
by: Raj Chudasama | last post by:
How do i bind multiple tables from an xml file to one data grid? like the following: <Histories> <called> <number> 323223</number> <number>2232</number> </called> <received> <number>...
4
by: dreaken667 | last post by:
I have a MySQL database containing 16 tables of data. Each table has a different number of columns and there are few common field names accross tables. I do have one master table with which I connect...
5
by: chrisbenett | last post by:
Hi all, I want to create an invoice number that looks like "YYMMDD01" which will increment with 1 for each invoice. But the next day, it will need to start at one again. Example: Today:...
28
by: wirejp | last post by:
You are correct. An invoice number relate to a particular country but there may be multiple records for different regions within this country under this invoice number. So I guess that the invoice...
3
by: wirejp | last post by:
Referencing post: -http://bytes.com/topic/access/answers/779498-sum-access-report-repeating-invoice I need some help with the calculation of invoice amounts on a Microsoft Access 2010 report. My...
0
by: vinpkl | last post by:
hi all i am filtering results of purchases made by customer. $qry = "select * from mytable" $result = mysql_query($qry); while($row=mysql_fetch_array($result) { echo $row;
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.