Type Mismatch after CDate?

  • Thread starter Thread starter Steven Britton via AccessMonster.com
  • Start date Start date
S

Steven Britton via AccessMonster.com

After I run the below I get a Type Mismatch, haven't I converted the String
to a Date that I can extract the MonthName from?

strResponse = strTkingPer
strMsg = "Enter a Tracking Period for the report data, or accept " _
& "the defaulted period which is the first day of the requested " _
& "range of the OBMS report[use 11/1/2004 format]. Clicking on CANCEL
" _
& "will not place any Tracking Period onto the datasheet:"
strTitle = "Report Tracking Period"
strResponse = InputBox(strMsg, strTitle, strResponse)
If strResponse <> "Base" Then
strResponse = CDate(strResponse)
strResponse = MonthName(strResponse)
End If

Thanks again to everyone out there that answers these questions!!!
 
If strResponse is declared as a String variable, then assigning the result
of the CDate function to the variable will implicitly convert it back to a
String again. Try this instead ...

strResponse = MonthName(CDate(strResponse))
 
Yes, strResponse is declared as a String variable. Having it return to a
string is OK, I only want to extract the Month Name for visual reason. I
did as you suggested and received a error:

Invalid procedure call or argument?

If I use strResponse = Year(CDate(strResponse)) I get 2005 and if I use:

strResponse = Month(CDate(strResponse)) I'll get 3???

Both of those are correct, but I would like to get March or Mar.

I tried:
strResponse = MonthName(CDate(strResponse),True) and
strResponse = MonthName(CDate(strResponse), False)

yet received the same error...
 
Format(CDate(strResponse), "mmm") will give you Jan, Feb, Mar..., while
Format(CDate(strResponse), "mmmm") will give you January, February, March...
 
Sorry Steven, I should have tested that before posting. It turns out that
MonthName wants a Long Integer, which is the number of the month in
question, so the expression would have to be ...

strResponse=MonthName(Month(CDate(strResponse)))

.... or you could use Format as in Doug's example.
 
Back
Top