Solved

Type mismatch: 'Format'

Posted on 2006-06-14
13
537 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
  • 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 69

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
 
LVL 69

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 69

Expert Comment

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

is the error raised by the VB compiler?
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now