Solved

Type mismatch: 'Format'

Posted on 2006-06-14
13
542 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 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

773 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