Forums

This topic is locked

Insert Date in Access db

Posted 19 May 2004 16:32:00
1
has voted
19 May 2004 16:32:00 Russell Marshall posted:
I am trying to add two feilds to an access db using the insert record behaviour but when I submit the page falls over.
If I add the price only without the date baing included in the insert behaviour all is fine.

I think I must have a problem with the date format.

The two fields are data and price.

The access db date field is set to shortdate but when I put the data in the text box as mm/dd/yy or mm/dd/yyyy or any other I have tried it does not work.

Any ideas anyone.

Thanks







Russell

Replies

Replied 19 May 2004 19:05:50
19 May 2004 19:05:50 Dave Thomas replied:
i usually have my date fields set like so..

field type : date/time
default value: date()

so it will grab the date by default on insert,

no messing , using formats, this can be done in dreamweaver or when your doing your code.

Regards,
Dave

[DWMX 2004]|[FlashMX 2004 Pro]|[Studio MX 2004]|[SQL]|[Access2000/2002]|[ASP/VBScript]|[XP-Pro]
If you like online gaming, please register @ www.nova-multigaming.com
Replied 19 May 2004 19:25:14
19 May 2004 19:25:14 Russell Marshall replied:
Many thanks

The problem is that I cannot use date() as i do not want to add the current date. It is for a holiday booking site and the date is the departure date.

Thanks

Russell

Russell
Replied 19 May 2004 19:40:15
19 May 2004 19:40:15 Dave Thomas replied:
in that case

i'd build the departure date as 3 seperate fileds.
departure_day
departure_month
departure_year

and have them select a date from a drop down like on all the other holiday sites.
---

one thing to check is in your code, dw, inserts a RunatServer DoDateTime piece of code, this gave me problems sometimes until i manually removed it.

a simple date field should give you not trouble whatsoever, you mind if i see the code and db?

Regards,
Dave

[DWMX 2004]|[FlashMX 2004 Pro]|[Studio MX 2004]|[SQL]|[Access2000/2002]|[ASP/VBScript]|[XP-Pro]
If you like online gaming, please register @ www.nova-multigaming.com
Replied 19 May 2004 20:06:56
19 May 2004 20:06:56 Russell Marshall replied:
No problem

I have created a test page that can de viewed at www.martynstravel.com/test.asp

The code is as follows, and an image showing the db table is on the page.

Thanks for helping

Davrus

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/CONadmin.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 & "?" & Server.HTMLEncode(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_CONadmin_STRING
MM_editTable = "tbldepartures"
MM_editRedirectUrl = ""
MM_fieldsStr = "txt_date|value|txt_price|value|fld_tourid|value"
MM_columnsStr = "fld_date|',none,NULL|fldprice|none,none,NULL|tourID|none,none,NULL"

' 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
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<form name="form1" method="POST" action="<%=MM_editAction%>">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="18%">Date </td>
<td width="82%"><input name="txt_date" type="text" id="txt_date"></td>
</tr>
<tr>
<td>Price</td>
<td><input name="txt_price" type="text" id="txt_price"></td>
</tr>
<tr>
<td> </td>
<td><input name="fld_tourid" type="hidden" id="fld_tourid" value="5"> </td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>

<input type="hidden" name="MM_insert" value="form1">
</form>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</body>
</html>


Russell
Replied 19 May 2004 20:16:04
19 May 2004 20:16:04 Russell Marshall replied:
I have found out what the problem is. It is me being careless.

I have called an access field "date".

Many thanks

Davrus

Russell
Replied 19 May 2004 20:22:55
19 May 2004 20:22:55 Dave Thomas replied:
doh <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

the old reserved word nightmare eh. lol

glad you fixed it m8

Regards,
Dave

[DWMX 2004]|[FlashMX 2004 Pro]|[Studio MX 2004]|[SQL]|[Access2000/2002]|[ASP/VBScript]|[XP-Pro]
If you like online gaming, please register @ www.nova-multigaming.com
Replied 20 May 2004 12:09:05
20 May 2004 12:09:05 Vince Baker replied:
Just to add to the old date problem questions, I have always solved the date issue by using a pop up calendar and a read only field, so the client picks a date and it is then entered into the read only field.

I have found this very successful and should anyone want to do the same, a simple search on google for popup calendar will return many examples.

Regards
Vince

DMX Talkzone Manager

Visit my home: www.chez-vince.com

VBScript | ASP | HTML | SQL | Oracle | Hosting

Reply to this topic