?
Solved

Type mismatch: 'Format'

Posted on 2006-06-14
13
Medium Priority
?
550 Views
Last Modified: 2013-12-03
Hi

I try to do this

cn.Execute "INSERT INTO testtable (testdate) VALUES(" + Format(now(), "yyyy-mm-ddThh:nn:ss") +  ")"

But I get the error


Type mismatch: 'Format'    

Any ideas?

Thanks!
0
Comment
Question by:amoran
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
13 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 16900947
Hi amoran,

try:

cn.Execute "INSERT INTO testtable (testdate) VALUES('" + Format(now(), "yyyy-mm-dd hh:nn:ss") +  "')"


Tim Cottee
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 16900998
Hi amoran,

You need delimiters (quotes) as Tim showed you but I don't your (first) error comes from there (but it would have cause one later for sure).

try replacing + with &:

cn.Execute "INSERT INTO testtable (testdate) VALUES('" & Format(now(), "yyyy-mm-dd hh:nn:ss") & "')"

Cheers!
0
 

Author Comment

by:amoran
ID: 16900999
Hi Tim

Still

 Type mismatch: 'Format'  

Thanks

Dates in my DB are like this
2006/04/28 10:00:00
Data Type Datetime
Lenght 8

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 70

Expert Comment

by:Éric Moreau
ID: 16901017
what about the & ?

the error is raised by the VB compiler?
0
 

Author Comment

by:amoran
ID: 16901051
The & gave me the same error
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 16901059
are you in vb6 ?

is the error raised by the VB compiler?
0
 

Author Comment

by:amoran
ID: 16901069
Its in SQL Server Enterprise Manager

Im setting up a Job

I use this code

Dim cn
set cn = createobject("ADODB.Connection")
cn.Open "Provider=SQLOLEDB;Persist Security Info=False;User ID=clientID;Data Source=tcp:x.x.x.x,1433;Database=mydb;Integrated Security=SSPI;"
cn.Execute "INSERT INTO testtable (testdate) VALUES('" & Format(now(), "yyyy-mm-dd hh:nn:ss") &  "')"
cn.Close
set cn = nothing
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 16901084
amoran,

Ahhh, so you don't actually have the same functions there. You only have vbscript not full vb functionality. Therefore you need to use
cn.Execute "INSERT INTO testtable (testdate) VALUES('" & FormatDateTime(now(), 0) &  "')"

Tim
0
 

Author Comment

by:amoran
ID: 16901152
Tim

Tried that but

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

=)

Thanks for the help guys

Increasing points
0
 

Author Comment

by:amoran
ID: 16901175
Should I be doing something like this

Format(myDateTime, "yyyy-mm-dd hh:nn:ss")

Or is there a VBScript equivalent?
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 120 total points
ID: 16901182
amoran,

Ok, that at least solves the initial problem though.
http://www.prezzatech.com/kb/articles/kb-1005-conversion_char_to_datetime.asp

Will help in guiding you to solve the rest.
Tim
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 16901189
amoran,

The thing is with the formatdatetime function, you don't have the same flexibility as with format, you only have certain fixed formats to choose from. Unless you build your own one, you need to resolve the conflict between the date time formats on your sql server.

Tim
0
 

Author Comment

by:amoran
ID: 16901209
I tried

cn.Execute "INSERT INTO testtable (testdate) VALUES('" & FormatDateTime(now(), "yyyy/mm/dd hh:nn:ss") &  "')"

but

Type mismatch: '[string: "yyyy/mm/dd hh:nn:ss"]'    
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question