Simple Expression Builder Question (1 Viewer)

Access77

New member
Local time
Today, 08:25
Joined
Aug 30, 2019
Messages
4
I am creating the Access expression builder to create a field in a table, drawing from other fields in the same table.

I have an existing date field in the table that has the format dd/mm/yy.

I want to get the month from this existing date field.

The expression I am using is:

& Month([Date])

This works, but for single digit months (eg January), only return 1

I need the returned value to be 01.

Can someone please assist.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:25
Joined
May 7, 2009
Messages
19,230
& Format(Month([Date]), "00")
 

Access77

New member
Local time
Today, 08:25
Joined
Aug 30, 2019
Messages
4
& Format(Month([Date]), "00")


I am getting the error message 'The expression cannot be used in a calculated column', though I think you are close.



I have tried variations of this, but so far without success.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:25
Joined
May 7, 2009
Messages
19,230
you are entering the expression in Calculated field.
try this expression:

IIf(Month([date]) & ""="","",IIf(Len(Month([date]) & "")<2,"0" & Month([date]) & "",Month([date]) & ""))
 

Access77

New member
Local time
Today, 08:25
Joined
Aug 30, 2019
Messages
4
you are entering the expression in Calculated field.
try this expression:

IIf(Month([date]) & ""="","",IIf(Len(Month([date]) & "")<2,"0" & Month([date]) & "",Month([date]) & ""))


Thanks that did it!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:25
Joined
Oct 29, 2018
Messages
21,467
Hi. Welcome to AWF! If it’s not too late yet, I would suggest changing the name of your field because Date is a reserved word and can be a cause of headaches later on.
 

Access77

New member
Local time
Today, 08:25
Joined
Aug 30, 2019
Messages
4
Hi. Welcome to AWF! If it’s not too late yet, I would suggest changing the name of your field because Date is a reserved word and can be a cause of headaches later on.


Thanks, my field is not named date. I just used this in the example.
 

Users who are viewing this thread

Top Bottom