Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date() and type mismatch

Status
Not open for further replies.

iisman

Technical User
Mar 6, 2005
85
CA
Code:
rsblog.Fields("data") = Date()

ahhh! I have been looking at this for hours.

getting the "type mismatch" error on this line of code. I know that means that there is a data mismatch so to speak, but i just can not find the error!!!

any suggestions? thanks!
 
Can check the .type which should be adDate=7.
[tt] wscript.echo rsblog.Fields("data").type[/tt]
 
Thanks tsuji,

I am sorry, I am unfamilliar with what you have written there...

from a google search, i see that it is a method of testing the .type. I am not sure how to use it though.

Thanks for the response.
 
If the script is server side:
Response.Write "Type of rsblog('data') = " & rsblog.Fields("data").Type
rsblog.Fields("data") = Date()

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV

Thanks for that. It will not execute, and gives me a type mismatch on that second line you have there.

Here is the entire clip of code that is involved:
(essentially, this is what is done when a form is submitted , and is meant to write the info to the db. nothing is passed for the date value, so there is an if statement to see that, and to set it equal to the current date using the Date() function. This is the line with the problem:

Code:
If data <> "" Then 
rsblog.Fields("data") = data
else
rsblog.Fields("data") = Date()
end if

Here is the full block of code...

Code:
if trim(request.form("fullsizeisSubmitted")) = "yup" then

Response.Buffer = True
Dim iMonth, iYear
iMonth=Request ("month")
iYear=Request ("year")
if iMonth = "" then iMonth = Month(Now)
sMonth=NameFromMonth(iMonth)
if iYear = "" then iYear = Year(Now)

Dim blog_id
Dim rsblog
Dim blog_autore
Dim blog_email
Dim blog_titolo
Dim blog_testo
Dim blnComments
Dim strMode
Dim strEmailSubject
Dim strEmailBody
Dim page
Dim Block
Dim msg
Dim errore
Dim data
Dim ora
Dim mese
Dim anno
Dim mese_inserimento
errore = false
page = Request.Form("page")
Block = Request.Form("Block")
strMode = Request.Form("strMode")

If strMode = "edit" Then blog_id = CLng(Request.Form("blog_id"))


If Trim(Request.form("blog_autore")) = "" Or Trim(Request.form("blog_titolo"))= "" Or Trim(Request.form("blog_testo"))= "" Then
	 errore = true
End If

blog_autore = Request.Form("blog_autore")
blog_email = Request.Form("email")
blog_titolo = Request.Form("blog_titolo")
blog_testo = Request.Form("blog_testo")

' Format user input and remove html tags
blog_autore = removeAllTags(blog_autore)
blog_email = removeAllTags(blog_email)
blog_titolo = removeAllTags(blog_titolo)

If strMode = "new" AND Ublogtype = "open" Then
blog_testo = removeAllTags(blog_testo)
blog_testo = UBBcode(blog_testo)
else
blog_testo = removemaligno(blog_testo)
End if
blog_testo = Replace(blog_testo, VbCrLf, "<br>")
' end format


data = Request.Form("data")
ora = Request.Form("ora")
blnComments = CBool(Request.Form("comments"))
mese = Request.Form("mese")
anno = Request.Form("anno")
If mese <> "" Then 
mese_inserimento =Right(CStr(100+mese), 2)
else
mese_inserimento =Right(CStr(100+Month(Date)), 2)
end if

Set rsblog = Server.CreateObject("ADODB.Recordset")

If errore = false then
If strMode = "edit" Then
	strSQL = "SELECT blog.* FROM blog WHERE blog.blog_id = " & blog_id & ";"	
Else
	strSQL = "SELECT Top 1 blog.* FROM blog;"
End If

rsblog.CursorType = 2

rsblog.LockType = 3
rsblog.Open strSQL, strCon

If NOT strMode = "edit" Then rsblog.AddNew

rsblog.Fields("blog_titolo") = blog_titolo
rsblog.Fields("blog_testo") = blog_testo
rsblog.Fields("blog_autore") = blog_autore
rsblog.Fields("blog_email") = blog_email



If data <> "" Then 
rsblog.Fields("data") = data
else
rsblog.Fields("data") = Date()
end if
If ora <> "" Then 
rsblog.Fields("ora") = ora
else
rsblog.Fields("ora") = Time()
end if
rsblog.Fields("mese") = mese_inserimento
If anno <> "" Then 
rsblog.Fields("anno") = anno
else
rsblog.Fields("anno") = Year(Date)
end if
rsblog.Fields("commenti") = blnComments
			
rsblog.Update
rsblog.Requery

	If blnEmail = True AND strMode <> "edit" Then
		strEmailSubject = strLangSubjectEmailNewBlog

		strEmailBody = strLangEmailHi
		strEmailBody = strEmailBody & "<br><br>" & strLangEmailBodyBlog1 & ""
		strEmailBody = strEmailBody & "<br>" & strLangEmailBodyBlog2 & ""
		strEmailBody = strEmailBody & "<br><br><b>" & strLangFormTitle & ": </b>" & blog_titolo
		strEmailBody = strEmailBody & "<br><br><b>" & strLangFormAuthor & ": </b>" & blog_autore
		strEmailBody = strEmailBody & "<br><b>" & strLangFormEmail & ": </b>" & email
		strEmailBody = strEmailBody & "<br><b>" & strLangFormText & ":</b><br>" & blog_testo
		
       	Dim objCDOMail
		Set objCDOMail = Server.CreateObject("CDONTS.NewMail")
		objCDOMail.From = Ublogname & " <" & emailamministratore & ">"
		objCDOMail.To = "<" & emailamministratore & ">"
        objCDOMail.Subject = strEmailSubject
		objCDOMail.Body = strEmailBody
		objCDOMail.BodyFormat = 0
		objCDOMail.MailFormat = 0
		objCDOMail.Importance = 1 
		objCDOMail.Send
		Set objCDOMail = Nothing
	
	End If


rsblog.Close
Set rsblog = Nothing




end if
%>



 
Replace this:
If data <> "" Then
with this:
If IsDate(data) Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
In that case, it seems string is always assumed, the everywhere assign value, use cstr() before assigning. (You worry about format later after you have a working script.)
[tt]
>rsblog.Fields("data") = Date()
rsblog.Fields("data") = cstr(Date())
>rsblog.Fields("ora") = Time()
rsblog.Fields("ora") = cstr(Time())
[/tt]
 
OOps, forget my last post.
You have to know what is the data type of the blog.data field.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks PHV,

I am still getting that pesky type mismatch error with the change you had suggested.. :(

Any other issues that you can spot?
 
You may try this:
rsblog.Fields("data") = FormatDateTime(Date, 2)
rsblog.Fields("ora") = FormatDateTime(Time, 3)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
THanks everyone, but still not juice, and getting the same error.

the frustrating part is that this all works when the pages are separate. I am combining them all in to one script, and getting the error there. I have checked, double checked, and checked again, and everything is exactly the same!
 
okay...PHV.....

that last one works, but it is inserting the date 1899, and not 2005 as it should.

THis has thrown me for a loop...how can this be resolved, and why is it choosing 1899?

Thanks again!
 
and actually...the date that it is entering is 12/30/1899

that makes no sense :(
 
ado
<adDate>
value 7
description: A Date value. A Double where the whole part is the number of days since December 30 1899, and the fractional part is a fraction of the day.
 
Seems you have an object named date somewhere ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Can the op really check the data type, response.write out the fields{"data").type? It does not help shooting randomly in the air and it's a waste of time.
 
If Not IsNothing
If Not Null, Empty

....

If IsNull(rsblog.Fields("data")) Then
Msgbox "is nothing
Else
Msgbox rsblog.Fields("data")
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top