Format Calculated Formula Field

SantasLittleHelper

Board Regular
Joined
Nov 25, 2016
Messages
77
I have a formula field in an access table which basically combines 2 fields. However, the calculated field changes the number field to remove the zeros. Is the below possible?

[TABLE="width: 500"]
<tbody>[TR]
[TD]Letters[/TD]
[TD]Numbers[/TD]
[TD]What the Calculated Field shows[/TD]
[TD]What I want the calculated field to show[/TD]
[/TR]
[TR]
[TD]AA[/TD]
[TD]0001[/TD]
[TD]AA1[/TD]
[TD]AA0001[/TD]
[/TR]
[TR]
[TD]AA[/TD]
[TD]0002[/TD]
[TD]AA2[/TD]
[TD]AA0002[/TD]
[/TR]
[TR]
[TD]BB[/TD]
[TD]0001[/TD]
[TD]BB1[/TD]
[TD]BB0001[/TD]
[/TR]
[TR]
[TD]BB[/TD]
[TD]0002[/TD]
[TD]BB2[/TD]
[TD]BB0002[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
I have a formula field in an access table which basically combines 2 fields
Just trying to be informative here, not condescending. Generally, you shouldn't be combining data in table fields but instead, use forms/reports for combining. To help you better going forward, provide more details around your issue, such as data types and field names.

That being said, the way to combine is to concatenate. = [Letters] & [Numbers]
However, you may have to coerce a number type to text (which you cannot do in a table field), and if you're really doing this in a table, I don't think the table will accept just any expression (what you're calling a formula). Thus to store this concatenation in a table, you may have no choice but to do this in an update query that creates the data via concatenation. Again, it's generally considered not to be best practice to keep both the separate values and the concatenation. Nor is it considered good practice to store calculations such as qty x price.
 
Upvote 0
if "numbers" is a numeric data type (number, rather than text) then you probably "see" 0001 only because it is displayed that way with formatting options. The underlying value would be merely the number.

If so, the calculated field should do the same formatting if you want to get the leading zeros:
= [Letters] & Format([Numbers], "0000")
 
Upvote 0
the calculated field should do the same formatting if you want to get the leading zeros:
= [Letters] & Format([Numbers], "0000")
I have just tried ths but when I try to save it, an error pops up saying this expression cannot be used in a calculated column.

Do you know how I can get around this?
 
Upvote 0
Do you know how I can get around this?
Sure. Follow the advice already given and don't use calculated fields in tables. Aside from that, the types of calculations allowed in a table is limited and this isn't one of them.
 
Upvote 0
I agree with not using the calculated fields for the most part... Although I have had a requirement to use them once myself before.

It wont accept format, however something like this should work:

Code:
[Letters] & String(4-Len([Numbers]),"0") & [Numbers]

If your number will ever be more than 4 digits you will get an error for that record.
 
Last edited:
Upvote 0
Along the same lines,
[Letters] & Right("0000" & [Numbers],4)

Which would also calculate wrong for numbers greater than 9999 and would return 0000 for null numbers.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,565
Messages
6,173,087
Members
452,501
Latest member
musallam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top