How do I convert an inout month number into a month name? (1 Viewer)

helen269

Registered User.
Local time
Today, 14:45
Joined
Feb 4, 2012
Messages
14
I have a report based on a query where in the query the user inputs a month from 1 - 12. How do I make the report say the name of the month instead of the inputted number?

The field in the query is constructed like this:

Field Month: Month([tbl_2_CustomerOrder.OrderDate])

Criteria [Input month (1-12)]



I've tried using =Format$([Month],"mmmm") but it always returns "January". What am I doing wrong?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:45
Joined
Aug 30, 2003
Messages
36,125
You already know that any record returned would be in that month, so just use the OrderDate field in the Format() function. By the way, you realize that you'll get multiple year's data with that criteria?
 

helen269

Registered User.
Local time
Today, 14:45
Joined
Feb 4, 2012
Messages
14
You already know that any record returned would be in that month, so just use the OrderDate field in the Format() function. By the way, you realize that you'll get multiple year's data with that criteria?


Thanks Paul.

I've just tried =Format$([OrderDate],"mmmm") but now I don't get anything, not even a #error.

And don't worry about the year, I have an input for the year as my first field in the query, the month is the second.
 

helen269

Registered User.
Local time
Today, 14:45
Joined
Feb 4, 2012
Messages
14
Thanks Paul.

I've just tried =Format$([OrderDate],"mmmm") but now I don't get anything, not even a #error.

Oops, mistake! What I actually get is "Input Year" followed by "Input Month" followed by "OrderDate" - because of the square brackets it wants me to input the order date.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:45
Joined
Aug 30, 2003
Messages
36,125
It's not because of the brackets, it's because it doesn't recognize the field name. What is the actual field name?
 

helen269

Registered User.
Local time
Today, 14:45
Joined
Feb 4, 2012
Messages
14
It's not because of the brackets, it's because it doesn't recognize the field name. What is the actual field name?


In the table and the form it's
OrderDate.

In the query it's
Month: Month([tbl_2_CustomerOrder.OrderDate])
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:45
Joined
Aug 30, 2003
Messages
36,125
Try with that full reference, even though it doesn't look right:


=Format$([tbl_2_CustomerOrder.OrderDate],"mmmm")
 

helen269

Registered User.
Local time
Today, 14:45
Joined
Feb 4, 2012
Messages
14
Try with that full reference, even though it doesn't look right:


=Format$([tbl_2_CustomerOrder.OrderDate],"mmmm")


It just comes up asking for a third input:

Enter Parameter Value
tbl_2_CustomerOrder.OrderDate


I already have a control box with the Month value in it which displays as a number so I get "Month: 6" for example instead of "Month: June". I'm going to try making a copy of that box and put the formatting stuff around it and see if that works....
 

helen269

Registered User.
Local time
Today, 14:45
Joined
Feb 4, 2012
Messages
14
It just comes up asking for a third input:

Enter Parameter Value
tbl_2_CustomerOrder.OrderDate


I already have a control box with the Month value in it which displays as a number so I get "Month: 6" for example instead of "Month: June". I'm going to try making a copy of that box and put the formatting stuff around it and see if that works....


Nope. It still comes up with "January".

I think I'll leave it as it is, it's only for an Access class assignment. The database works and the tutor can take the month as a number and it'll still pass.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:45
Joined
Aug 30, 2003
Messages
36,125
If you want to post the db here, we can figure it out.
 

helen269

Registered User.
Local time
Today, 14:45
Joined
Feb 4, 2012
Messages
14
If you want to post the db here, we can figure it out.


Really? That's very good of you, thanks! :)

When it opens you'll need the second from last item on the switchboard. There's not much data in it but enter 2011 for the year and either 6, 7 or 8 for the month.

Thanks again! :)
 

Attachments

  • 18.3 - HDe'Ath - BuzzComm database - 22_2012-02-29.mdb
    1.2 MB · Views: 160

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:45
Joined
Aug 30, 2003
Messages
36,125
Ah, it's because the date field isn't returned by the query, thus unavailable in the report. You can have a textbox like:

=MonthName([Month])

Fair warning, it will error if there's also a textbox with the same name as the field, which is currently the case.
 

helen269

Registered User.
Local time
Today, 14:45
Joined
Feb 4, 2012
Messages
14
Ah, it's because the date field isn't returned by the query, thus unavailable in the report. You can have a textbox like:

=MonthName([Month])

Fair warning, it will error if there's also a textbox with the same name as the field, which is currently the case.

Ok, I deleted the existing Month boxes in the report, both the text and control box, and put in a control box your =MonthName([Month]) and it's giving a #error.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:45
Joined
Aug 30, 2003
Messages
36,125
Here you go.
 

Attachments

  • 18.3 - HDe'Ath - BuzzComm database - 22_2012-02-29.zip
    255.1 KB · Views: 361

helen269

Registered User.
Local time
Today, 14:45
Joined
Feb 4, 2012
Messages
14
Here you go.

Wow, that's amazing, thank you!

But I put in exactly the same as this. You've even left in the text label box. I want to understand this, what did you do to make it work?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:45
Joined
Aug 30, 2003
Messages
36,125
I had to change the name of the textbox, which you'll see is now "txtMonth".
 

helen269

Registered User.
Local time
Today, 14:45
Joined
Feb 4, 2012
Messages
14
I had to change the name of the textbox, which you'll see is now "txtMonth".


Of course! So when I deleted the original month label and control boxes - after making a copy of the control box - I didn't eliminate the problem as the copy of the control box that I modified the contents of still had the original conflicting name. Damn!

Anyway, thank you very much indeed for sorting that out for me and explaining where I went wrong. I'll know what to look out for in future in a similar situation.

Thank you! :)
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:45
Joined
Aug 30, 2003
Messages
36,125
Happy to help!
 

Users who are viewing this thread

Top Bottom