Solved

Generate Custom Number and assign to another field on the form

Posted on 2014-01-06
10
519 Views
Last Modified: 2014-01-12
I am generating a custom record number based on three fields:
Type
SO#
WOID

The custom number is created using the following equation:
= [SO#] & Left([Type],1) & [WOID]

I first used this equation as the source for the WorkOrderNumber field and the custom number was not saved in the field in the table.

So I then created an unbound field to capture the custom number and then I set the WorkOrderNumber field equal to the unbound field.
Neither saves the the custom number and I would like to save this number since it should not change once assigned.

Thoughts?
0
Comment
Question by:btgtech
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 12

Expert Comment

by:pdebaets
ID: 39761251
Use a query based on the table instead of the table for your form recordsource. Create a field in the query that concatenates the 3 fields. Now you can use a bound text box to display the custom number.
0
 
LVL 84
ID: 39761881
Peter has pointed you in the right direction, but to expand:

You should not save values like that in a table. Instead, since you always have the "root" values available (i.e. the Type, SO#, and WOID fields) just "build up" that value when you need it. The only reason for that value is for human readability, and you can run into troubles down the road if you stored "calculated" values like this. For example, what if the Type changes? You'd have to be sure that you also update that calculated value, and if the user somehow gets to the table and changes it directly, your data becomes flawed.

So save the "root" values, and use a query as Peter suggests.
0
 

Author Comment

by:btgtech
ID: 39761994
But, if someone mistakenly changes the SO# or the type, then the number will change and I would rather not have to lock down the fields.
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 84
ID: 39762162
then the number will change
The number would not change unless you put code in place to insure it changes. That's the entire concept behind NOT storing calculated values, and instead storing the root values - changes made to the "root" values would be reflected in your forms and reports and queries without you having to do anything further. If you stored the full calculated value, you'd have to insure you make the required data changes in all those locations to insure you write back the calculated value correctly.
I would rather not have to lock down the fields.
I'm not sure what you mean by this, but you don't have to lock down anything (and you can't do that in Access anyway).
0
 
LVL 35

Accepted Solution

by:
PatHartman earned 500 total points
ID: 39762980
You could save the calculated field in the Form's BeforeUpdate event.  I also do not like creating "meaningful" fields like this because as has been pointed out, changing one of the underlying components either results in a new value if you did it right and didn't store the value but calculated it instead and if you do it wrong and store the value, it doesn't change but now it will no longer relate to the rest of the record.  You need to come to grips with the issue and decide which is best for you.

If Me.CalcID & "" = "" Then
    [SO#] & Left([Type],1) & [WOID]
End If

Open in new window

0
 

Author Comment

by:btgtech
ID: 39763391
The Work Order number is a number that we need to set once.  It does not change for the duration of the work order and for the most part the only time that the other parts may change is due to an entry error.

I will just use the calculated field.
0
 
LVL 84
ID: 39767543
for the most part the only time that the other parts may change is due to an entry error.
I've been doing this a long time, as has Pat, and my experience has always been that forcing non-standard behavior (like this) is never a good idea.

But it's your data, and you're the one who'll have to deal with the mess ...

Also, you really should not have accepted my comment as your "solution". Pat's answer will provide you with the method to store your calculated value, so I've asked the Moderators to change the award.
0
 
LVL 35

Expert Comment

by:PatHartman
ID: 39768002
Thanks Scott.
0
 

Author Comment

by:btgtech
ID: 39775602
OK,
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question