Skip to main content
Inspiring
August 29, 2006
Question

INSERT & UPDATE changing date format to mm/dd/yyyy!!!

  • August 29, 2006
  • 2 replies
  • 498 views
I have INSERT & UPDATE ASP/VB forms which have a date field which submits to
Access....except when the date is entered as dd/mm/yyyy, it decides to
convert it to mm/dd/yyyy....absolutely terrific!! :o((

I've added this:
<% Session.LCID = 2057 %>

I've checked the date format, I've done absolutely everything I can think
of, and can source on the newsgroups, but NOTHING.
What, on earth, is going on??????????????

If anyone can help save me from this madness, please tell me why this is
happening?
I'm using ASP/VB, with Access on a Windows server and, up until now, I've
never had this problem.

Here's my INSERT code:

<%@LANGUAGE="VBSCRIPT"%>
<% Session.LCID = 2057 %>
<!--#include file="../Connections/dsnNAME.asp" -->
<%
Dim MM_editAction
MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" &
Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
Dim MM_abortEdit
MM_abortEdit = false
%>
<%
' IIf implementation
Function MM_IIf(condition, ifTrue, ifFalse)
If condition = "" Then
MM_IIf = ifFalse
Else
MM_IIf = ifTrue
End If
End Function
%>
<%
If (CStr(Request("MM_insert")) = "form1") Then
If (Not MM_abortEdit) Then
' execute the insert
Dim MM_editCmd

Set MM_editCmd = Server.CreateObject ("ADODB.Command")
MM_editCmd.ActiveConnection = MM_dsnNAME_STRING
MM_editCmd.CommandText = "INSERT INTO tblNews (newstitle, newsdate,
newsenddate, thumbnail, largeimage, newstextsnip, newstext, emailcontact,
urllink, [include]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 202,
1, 75, Request.Form("newstitle")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 135,
1, -1, MM_IIF(Request.Form("newsdate"), Request.Form("newsdate"), null)) '
adDBTimeStamp
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 135,
1, -1, MM_IIF(Request.Form("newsenddate"), Request.Form("newsenddate"),
null)) ' adDBTimeStamp
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 202,
1, 75, Request.Form("thumbnail")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 202,
1, 75, Request.Form("largeimage")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param6", 203,
1, 536870910, Request.Form("newstextsnip")) ' adLongVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param7", 203,
1, 536870910, Request.Form("newstext")) ' adLongVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param8", 202,
1, 75, Request.Form("emailcontact")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param9", 202,
1, 75, Request.Form("urllink")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param10", 5,
1, -1, MM_IIF(Request.Form("include"), 1, 0)) ' adDouble
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

' append the query string to the redirect URL
Dim MM_editRedirectUrl
MM_editRedirectUrl = "confirm.htm"
If (Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
Response.Redirect(MM_editRedirectUrl)
End If
End If
%>

Thanks.
Nath.


This topic has been closed for replies.

2 replies

November 6, 2006
I'm running into the same problem but to some extend I think this has alot to do with the differences in Windows XP and Windows 2000 lIS and how it sets the locale.
In any case the Dreamweaver Update/Insert Behavoiours should give programmer the option of converting to a ISO format date eg YYYYMMDD 24:MM:SS or some other format without breaking the code behaviour recognition.
Any hints on this would be useful?
Inspiring
August 29, 2006
Well, I've established that it's DW8.0.2 that is causing this strange
occurence.
Reverted back to previously created versions of my INSERT/UPDATE form pages
(created in DWMX) and it all works fine!!
I think that makes the whole situation even more frustrating because I had
HUGE problems with this back in 2003/2004, and resolved it.
Now I've upgraded to DW8.0.2 and it's all gone "ape" again. <sigh>

Any ideas, looking at the code in my initial post, why this is happening?
For comparison here is the same INSERT created in DWMX that WORKS:

<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../Connections/dsnNAME.asp" -->
<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert")) = "form1") Then

MM_editConnection = MM_dsnNAME_STRING
MM_editTable = "tblNews"
MM_editRedirectUrl = "confirm.htm"
MM_fieldsStr =
"newstitle|value|newsenddate|value|thumbnail|value|largeimage|value|newstextsnip|value|newstext|value|emailcontact|value|urllink|value|include|value"
MM_columnsStr =
"newstitle|',none,''|newsenddate|',none,NULL|thumbnail|',none,''|largeimage|',none,''|newstextsnip|',none,''|newstext|',none,''|emailcontact|',none,''|urllink|',none,''|include|none,1,0"

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")

' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And
Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues

If (CStr(Request("MM_insert")) <> "") Then

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ")
values (" & MM_dbValues & ")"

If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%>

This type of thing does my HEAD in.
Nath.


"tradmusic.com" <sales@NOSHPAMtradmusic.com> wrote in message
news:ed2a54$hrc$1@forums.macromedia.com...
>I have INSERT & UPDATE ASP/VB forms which have a date field which submits
>to Access....except when the date is entered as dd/mm/yyyy, it decides to
>convert it to mm/dd/yyyy....absolutely terrific!! :o((
>
> I've added this:
> <% Session.LCID = 2057 %>
>
> I've checked the date format, I've done absolutely everything I can think
> of, and can source on the newsgroups, but NOTHING.
> What, on earth, is going on??????????????
>
> If anyone can help save me from this madness, please tell me why this is
> happening?
> I'm using ASP/VB, with Access on a Windows server and, up until now, I've
> never had this problem.
>
> Here's my INSERT code:
>
> <%@LANGUAGE="VBSCRIPT"%>
> <% Session.LCID = 2057 %>
> <!--#include file="../Connections/dsnNAME.asp" -->
> <%
> Dim MM_editAction
> MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
> If (Request.QueryString <> "") Then
> MM_editAction = MM_editAction & "?" &
> Server.HTMLEncode(Request.QueryString)
> End If
>
> ' boolean to abort record edit
> Dim MM_abortEdit
> MM_abortEdit = false
> %>
> <%
> ' IIf implementation
> Function MM_IIf(condition, ifTrue, ifFalse)
> If condition = "" Then
> MM_IIf = ifFalse
> Else
> MM_IIf = ifTrue
> End If
> End Function
> %>
> <%
> If (CStr(Request("MM_insert")) = "form1") Then
> If (Not MM_abortEdit) Then
> ' execute the insert
> Dim MM_editCmd
>
> Set MM_editCmd = Server.CreateObject ("ADODB.Command")
> MM_editCmd.ActiveConnection = MM_dsnNAME_STRING
> MM_editCmd.CommandText = "INSERT INTO tblNews (newstitle, newsdate,
> newsenddate, thumbnail, largeimage, newstextsnip, newstext, emailcontact,
> urllink, [include]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
> MM_editCmd.Prepared = true
> MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 202,
> 1, 75, Request.Form("newstitle")) ' adVarWChar
> MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 135,
> 1, -1, MM_IIF(Request.Form("newsdate"), Request.Form("newsdate"), null)) '
> adDBTimeStamp
> MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 135,
> 1, -1, MM_IIF(Request.Form("newsenddate"), Request.Form("newsenddate"),
> null)) ' adDBTimeStamp
> MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 202,
> 1, 75, Request.Form("thumbnail")) ' adVarWChar
> MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 202,
> 1, 75, Request.Form("largeimage")) ' adVarWChar
> MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param6", 203,
> 1, 536870910, Request.Form("newstextsnip")) ' adLongVarWChar
> MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param7", 203,
> 1, 536870910, Request.Form("newstext")) ' adLongVarWChar
> MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param8", 202,
> 1, 75, Request.Form("emailcontact")) ' adVarWChar
> MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param9", 202,
> 1, 75, Request.Form("urllink")) ' adVarWChar
> MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param10", 5,
> 1, -1, MM_IIF(Request.Form("include"), 1, 0)) ' adDouble
> MM_editCmd.Execute
> MM_editCmd.ActiveConnection.Close
>
> ' append the query string to the redirect URL
> Dim MM_editRedirectUrl
> MM_editRedirectUrl = "confirm.htm"
> If (Request.QueryString <> "") Then
> If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then
> MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
> Else
> MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
> End If
> End If
> Response.Redirect(MM_editRedirectUrl)
> End If
> End If
> %>
>
> Thanks.
> Nath.
>