Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Finding Next Month as Text May, June
Tom Juric 
      
2 days ago
I want to find today's MONTH (as text) and today's MONTH + 1xMonth (as text). I am getting ERROR:Type mismatch in the ElseIf line of code.   In the code below:

CurrentMonthText choosing CURRENT should=May (for this month)------Today's Month
DesiredMonth choosing NEXT should =June------------Today's MONTH + 1xMonth

********CODE********
CurrentMonthText = MonthName(Month(Date))....This Works

If DesiredMonth = "CURRENT" Then
  ReportMonth = CurrentMonthText  ...........This works
ElseIf DesiredMonth = "NEXT" Then
  ReportMonth = DateAdd("m", 1, MonthName(Month(Date)))
Else
Endif

*****END CODE*******

Can anyone tell me where ia went wrong?
Donald Blackwell  @Reply  
       
2 days ago
Have you tried:

MonthName(Month(Date) + 1)

For next month?

I haven't tested, on my phone but that's the first thing that popped into my head.
Kevin Robertson  @Reply  
          
2 days ago
You can't add a date value to a text string. This is why you are getting a Type Mismatch Error.

Here is a sample. I used variable but you could easily modify the code to use form fields if you wish.
The important variable is d As Date used to add one month to the current date.

Dim currentMonthText As String, desiredMonth As String, reportMonth As String
Dim d As Date
    
currentMonthText = MonthName(Month(Date))
desiredMonth = "CURRENT"

If desiredMonth = "CURRENT" Then
    reportMonth = currentMonthText
ElseIf desiredMonth = "NEXT" Then
    d = DateAdd("m", 1, Date)
    reportMonth = MonthName(Month(d))
End If
    
MsgBox reportMonth
Darrin Harris  @Reply  
     
2 days ago
I think we need to know how desiredmonth is determined?

Kevin the If block will always be current? desiredmonth will never be next
Kevin Robertson  @Reply  
          
2 days ago
Yeah. But I just set it up like that as an example. It's the wee hours of the morning here otherwise I would have built a full example with form fields and either a Combo Box or an Option Group to select Desired Month.
Darrin Harris  @Reply  
     
2 days ago
I know how that feels
Tom Juric OP  @Reply  
      
32 hours ago
DesiredMonth is a word, either CURRENT or NEXT and comes from an INPUT box by the user. "It is determined as What month report data do you want to see? This month data (CURRENT) or Next month data (NEXT)."  If CURRENT, I will determine the text value of the current month (MAY). If NEXT, I will determine the text value of the next month (June). RecordSoure will be based on a field containing the "text month". I determine this last data using DateAdd function:
( ReportMonth = DateAdd("m", 1, MonthName(Month(Date)))
Donald Blackwell  @Reply  
       
30 hours ago
You'll get a type mismatch using DateAdd("m", 1, MonthName(Month(Date))) because the DateAdd function is looking for the following types of parameters:

1st: String "m" defining you interval
2nd: Number, the number of intervals to add/subtract
3rd: Date (Variant), the date to add the number of intervals to

The problem is that you are trying to add 1 month to the date "May" which is not a valid date.

The solution I suggested above would be:

     ReportMonth = MonthName(Month(Date)+1)

Which would be:

     ReportMonth = MonthName(5 + 1)

or

     ReportMonth = "June"

Since Date is a number, Month(Date) would evaluate to a # between 1 and 12 (5, currently) and then 5 + 1 = 6 which MonthName(6) evaluates to "June"

If you want to keep the DateAdd Notation, you could also use:

     ReportMonth = MonthName(Month(DateAdd("m", 1, Date)))

Tom Juric OP  @Reply  
      
5 hours ago
Thank you all for your input.  Donald's answer (DateAdd) gave the perfect solution.  My hat is off to all y'all
Donald Blackwell  @Reply  
       
4 hours ago
Always happy to help
Add a Reply Upload an Image
Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/29/2026 4:34:03 PM. PLT: 1s