Solved

Type mismatch: 'Format'

Posted on 2006-06-14
13
546 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month9 days, 9 hours left to enroll

623 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