Format Function = Type Mismatch

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I cannot seem to get the Format Function working in VBA. I have simplified my
code to the point of:

MyStr = Format(Now, "Long Date")

But it still brings up bring up "Run-Time Error 13/ Type Mismatch" every
time. Am I leaving something out?
 
Your code works for me. It tried this:
Sub Testit()
Dim MyStr As String
MyStr = Format(Now, "Long Date")
End Sub
 
Furthermore, the following does work:

MyStr=FormatDateTime(Now, vbLongDate)

But not:

MyStr=FormDateTime(Now, "d mmm yyyy")

Any thoughts?
 
By some chance, do you have a variable named Now in your code? If yes,
ACCESS is trying to use that variable and not the Now() function.

Does this work:

MyStr = Format(Now(), "Long Date")

Or this:

MyStr = Format(Date(), "Long Date")
 
I've tried different data types, but same error every time.

I did a bit of googling, and I'm beginning to think Tim F was right about it
being VBScript, as the Format Function does not work in VBScript, only
FormatDateTime, which - from what I have gathered - cannot be customised in
terms of date formats.

I don't know much about VBScript. I thought I was using VBA - how is that I
am not?

Sorry about the stupidity. Thanks for your help Ken.
 
..mdb? .adp? DataAccessPage?

Only place within normal ACCESS that you'd be running VBScript is within a
Data Access Page.

If you're running this in a regular .mdb file in a class module, then you
may have a References error. Check your references and see if any are marked
as "MISSING".
--

Ken Snell
<MS ACCESS MVP>
 
Back
Top