Displaying Month on a Form

cornishteeth

Board Regular
Joined
Dec 6, 2002
Messages
117
I have a form that runs off of a query. I use the Month Function to ask user to enter a number (1-12) to pull data for that specific month.

Month([DAYS DATE])

Works fine. On my form though, I want the month to be displayed. Is there a way to have the actual month be displayed on the form. I tried using the MonthName Function, but kept getting errors. Any suggestions.

Frank
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
MonthName should work - were you passing it a numeric or text value instead of a date value?

DateSerial is a useful function to ensure that you've really got a 'date' variable.
 
Upvote 0
I'm guessing that this database is relatively new. When you have two years worth of data then you are going to run into problems as typing in 6 for June will return June for EVERY year in your database which, no doubt, you won't want.

As has been said above, the best way is to use the DateSerial function to create a range in order to have perfect criteria:

Between DateSerial(Year, Month, 1) And DateSerial(Year, Month, Day)


With a date, you can easily get the month name by using the Format() function.


=Format(myDate, "mmmm")
 
Upvote 0
I am guessing that you are having the query ask for the criteriaa, instead set up a control on the form for the user to pick their date from and link the criteria of the query to this.

HTH

Peter
 
Upvote 0
I have been reading up on the DateSerial function and don't see where it would fit in my situation. I understand that after 2 years, I will be obtaining erroneous data. Never thought of it that way. How would I go about implementing this function into my own database. I see I know nothing of VB, so posting code won't help unless you give me detailed instructions. Secondly, to reiterate my problem, I have a query that asks the user for a month by number. That in turn gives me all data from that month. I was attempting to display the month on my form. Is there a way to have the actual month be displayed on the form?

Thanks,

Frank
 
Upvote 0
Figured out the DateSerial Function. I do not need the Day in there. How would I arrange it to where user enters month/year vice month/day/year.

Thanks,

Frank
 
Upvote 0
cornishteeth said:
Figured out the DateSerial Function. I do not need the Day in there. How would I arrange it to where user enters month/year vice month/day/year.

Although you don't need a specific day, it's still advised to put the 1st of the month and the last of the month into the query to create the date range.


I don't have to explain any VBA as I haven't mentioned any VBA.
 
Upvote 0
Query Criteria: Set [Enter Month] as a Parameter

Between DateSerial(Year(Date()),[Enter Month],1) And DateAdd("m",1,DateSerial(Year(Date()),[Enter Month],1))-1


This will return all records for the selected month within the current year. I'd recommend you request the year also from the user.

If you do this, the set [Enter Year] as a Parameter and change the criteria to:

Between DateSerial([Enter Year],[Enter Month],1) And DateAdd("m",1,DateSerial([Enter Year],[Enter Month],1))-1


Personally I'd put two textboxes on a form and let the user specify any range they so wished - why restrict them to a month all the time? By having two textboxes they can pick to look at info for one day, one week, one month, three months, six months, 23 days, one year, ten years, etc.

So much better.

It's even shorter for criteria purposes.

Between [Forms]![MyForm]![txtStartDate] And [Forms]![MyForm]![txtEndDate]


where MyForm is the name of your form and txtStartDate and txtEndDate are the names of the textboxes.
 
Upvote 0

Forum statistics

Threads
1,221,707
Messages
6,161,416
Members
451,705
Latest member
Priti_190

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