Format Function = Type Mismatch

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?
 
D

Duane Hookom

Your code works for me. It tried this:
Sub Testit()
Dim MyStr As String
MyStr = Format(Now, "Long Date")
End Sub
 
G

Guest

Furthermore, the following does work:

MyStr=FormatDateTime(Now, vbLongDate)

But not:

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

Any thoughts?
 
K

Ken Snell [MVP]

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")
 
G

Guest

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.
 
K

Ken Snell [MVP]

..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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top