473,513 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unique calculation for a field in a table

1 New Member
After searching a long time.... I found no answer to my question. So here it is.

I have a table with:
[InvoicesID](Autonumber);[ContactID](Number);[Date](date);[InvoicesNumber](Number);[InvoicesCal](Calculated)


At the moment I have a calculation:[ContactID]+100&"-"&Year([Date])&"-"&[InvoicesNumber]=[InvoicesCal]
[ContactID] is also my customer number. [Date] the year. [InvoicesNumber] is a manual input.

[InvoicesCall has to be a unique calculation.
As an example:106-2013-001 This has to be a unique calculation.
Another example:108-2013-001
Another example:106-2013-002

My problem is the manual input of the field [InvoicesNumber]. Chance of human error with results in a not unique calculation.
I need [InvoicesNumber] to be like an autonumber but individual for every [ContactID].

What is the best approach here?
Aug 19 '13 #1
3 2152
zmbd
5,501 Recognized Expert Moderator Expert
Normally, calculated fields are not stored within the table except for historical/auditing reasons which an Invoice number may very well be such a need; however, at first glance it appears that the entire field value could be built in a query calculated field depending on how the value for [InvoicesNumber] is determined.


Therefore, we need just a little more information:

1) What version of Access are you using?
2) What are you currently using to create the invoice, is this all manual or some other method?
3) How is the value of [InvoicesNumber] determined?
Aug 19 '13 #2
ADezii
8,834 Recognized Expert Expert
Just subscribing for now, will Post a possible solution later.
Aug 20 '13 #3
ADezii
8,834 Recognized Expert Expert
I am literally running out the door, but the following Function will return the next Sequential Invoice Number based on the Contact ID passed to it. If the ID does not exist it will create it in the Format of XXX-YYYY-001. It is based on several assumptions - any questions feel free to ask.
Expand|Select|Wrap|Line Numbers
  1. Public Function fGenerateInvoiceNum(intContactID As Integer) As String
  2. Dim strSQL As String
  3. Dim MyDB As DAO.Database
  4. Dim rst As DAO.Recordset
  5.  
  6. strSQL = "SELECT * FROM Table1 WHERE Val(Left$([InvoicesNumber],3)) = " & intContactID
  7.  
  8. Set MyDB = CurrentDb
  9. Set rst = MyDB.OpenRecordset(strSQL, dbOpenSnapshot)
  10.  
  11. With rst
  12.   If .BOF And .EOF Then     'No Records for the ContactID (intContactID), create New
  13.     fGenerateInvoiceNum = CStr(intContactID) & "-" & CStr(Year(Date)) & "-001"
  14.   Else
  15.     'Record(s) with Contact ID exist, move to the Last
  16.     'Record then Increment
  17.     .MoveLast
  18.     fGenerateInvoiceNum = Left$(![InvoicesNumber], 9) & Format$(Val(Right$(![InvoicesNumber], 3)) + 1, "000")
  19.   End If
  20. End With
  21.  
  22. rst.Close
  23. Set rst = Nothing
  24. End Function
Aug 20 '13 #4

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

Similar topics

6
3810
by: Rey | last post by:
How can I update every record of a given table one by one. I need to update a field (date) with a different, random date for each record. loop { generate random date; update one record with...
1
1508
by: Mike | last post by:
I have a dataset that I need to validate. Here an example similar to what I need to do: <Company> <Employee> <Name>...</Name> <EmployeeID>1234</EmployeeID> </Employee> <Employee>...
0
1204
by: steve | last post by:
Hi all, Come across a situation I cannot figure how to work out. Im relatively new to access but have looked around and tried everything to my knowledge. I've developed an application whereby...
9
1866
by: jasonrholland | last post by:
i have to build a table within access that receives it's information from an ASP web page and generates the primary key, with numbers and letters, from the data submitted. a numer would be like...
1
2208
by: sgmarty | last post by:
Hi, I have an interesting problem. Without using reduncant data, how can I design a calculation field to get a running total from values in different records? I'm designing a usage/month report, and...
2
2423
by: mcyi2mr3 | last post by:
hi all ive been looking on the mysql site but i cant find the syntax to set a collumn in an existing table to be unique. could someone please give an example of how to do this. i believe it...
0
1289
by: kalyanakrishna | last post by:
I am not able to create a trigger on Text field table Comments will be appriciatable.
4
4978
by: wrldruler | last post by:
Hello, First, I know it's against "Access Law" to save calculations in a table, but....I want/need to. I currently have sub-totals being calculated inside a form, using DMax, DCount, and...
23
2887
klarae99
by: klarae99 | last post by:
In Access 2003 I am creating an Inventory Database from scratch. There are two tables (tblProductInformation and tblSubProducts) that I am trying to use in a queary to determine the number of Items...
11
2668
by: Xaysana12345 | last post by:
Hi there, I am having problem with form and report calculation fields showing #Num. ex. fieldA/fieldB if either fieldA or B=null, in the result field obtains #Num. How can I figure out? ...
0
7158
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
7535
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...
1
7098
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...
0
7523
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...
1
5085
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...
0
4745
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...
0
3232
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...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.