Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access_asp thread: stil dont get it! date from 3 pop menus


Message #1 by jake williamson 28 <jake.williamson@2...> on Wed, 24 Apr 2002 15:07:57 +0100
ok, i know al lot of you have already helped me with this but it just ain't
workin!! i understand the theory completely but no joy!!

all i wanna do is get the values from three pop up menus, join them together
and insert them!

the the three popups are mnuDay mnuMonth mnu Year - put them together to
equal a variable completeDate and insert that into a database table
CUSTOMERS, column DATEOFTRAVEL

the bellow is the scrip (its taken from a much bigger form that all works).
the code i've been advised to use is in there on lines 23/27 - it just dont
work! a line goes into the database but no date is entered.

any advice would be great (and apologies again for banging on about this!)

cheers,

jake


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

MM_editAction = CStr(Request("URL"))
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")) <> "") Then

  mnuMonth = Request.Form("mnuDay")
  mnuDay = Request.QueryString("mnuMonth")
  mnuYear = Request.QueryString("mnuYear")

  completeDate = mnuDay & "/" & mnuMonth & "/" & mnuYear

  MM_editConnection = MM_connMtm_STRING
  MM_editTable = "CUSTOMERS"
  MM_editRedirectUrl = "confirm.asp"
  MM_fieldsStr  = "completeDate|value"
  MM_columnsStr = "DATEOFTRAVEL|#,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 i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(i+1) = CStr(Request.Form(MM_fields(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

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

  ' create the sql insert statement
  MM_tableValues = ""
  MM_dbValues = ""
  For i = LBound(MM_fields) To UBound(MM_fields) Step 2
    FormVal = MM_fields(i+1)
    MM_typeArray = Split(MM_columns(i+1),",")
    Delim = MM_typeArray(0)
    If (Delim = "none") Then Delim = ""
    AltVal = MM_typeArray(1)
    If (AltVal = "none") Then AltVal = ""
    EmptyVal = MM_typeArray(2)
    If (EmptyVal = "none") Then EmptyVal = ""
    If (FormVal = "") Then
      FormVal = EmptyVal
    Else
      If (AltVal <> "") Then
        FormVal = AltVal
      ElseIf (Delim = "'") Then  ' escape quotes
        FormVal = "'" & Replace(FormVal,"'","''") & "'"
      Else
        FormVal = Delim + FormVal + Delim
      End If
    End If
    If (i <> LBound(MM_fields)) Then
      MM_tableValues = MM_tableValues & ","
      MM_dbValues = MM_dbValues & ","
    End if
    MM_tableValues = MM_tableValues & MM_columns(i)
    MM_dbValues = MM_dbValues & 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
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<form name="insertDate" method="POST" action="<%=MM_editAction%>">
<table border="0" cellspacing="3" cellpadding="0">
<tr>
<td class="mtmBody">
<select name="mnuDay">
<option value="no choice" selected>no choice</option>
<option value="01">01</option>
</select>
</td>
<td class="mtmBody">
<select name="mnuMonth">
<option value="no choice" selected>no choice</option>
<option value="01">01</option>
</select>
</td>
<td class="mtmBody">
<select name="mnuYear">
<option value="no choice" selected>no choice</option>
<option value="2000">2000</option>
</select>
</td>
<td class="mtmBody">
<input type="submit" name="Submit" value="Submit">
</td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="true">
</form>
</body>
</html>

Message #2 by "Serge Wagemakers" <swagemakers@d...> on Wed, 24 Apr 2002 18:10:01 +0200
Jake,

AFAIK, the line where the assignmentstatement : MM_fieldsStr  
"completeDate|value"
", does not produce the intended date you wanted but the text "completeDate"
which obviously is not a date.

If the date is to be inserted in Access try this:

MM_fieldsStr = "#" & completeDate & "#|value"
instead of
MM_fieldsStr = "completeDate|value"

HTH

Serge

----- Original Message -----
From: "jake williamson 28" <jake.williamson@2...>
To: "Access ASP" <access_asp@p...>
Sent: Wednesday, April 24, 2002 4:07 PM
Subject: [access_asp] stil dont get it! date from 3 pop menus


>
> ok, i know al lot of you have already helped me with this but it just
ain't
> workin!! i understand the theory completely but no joy!!
>
> all i wanna do is get the values from three pop up menus, join them
together
> and insert them!
>
> the the three popups are mnuDay mnuMonth mnu Year - put them together to
> equal a variable completeDate and insert that into a database table
> CUSTOMERS, column DATEOFTRAVEL
>
> the bellow is the scrip (its taken from a much bigger form that all
works).
> the code i've been advised to use is in there on lines 23/27 - it just
dont
> work! a line goes into the database but no date is entered.
>
> any advice would be great (and apologies again for banging on about this!)
>
> cheers,
>
> jake
>
>
> <%@LANGUAGE="VBSCRIPT"%>
> <!--#include file="Connections/connMtm.asp" -->
> <%
> ' *** Edit Operations: declare variables
>
> MM_editAction = CStr(Request("URL"))
> 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")) <> "") Then
>
>   mnuMonth = Request.Form("mnuDay")
>   mnuDay = Request.QueryString("mnuMonth")
>   mnuYear = Request.QueryString("mnuYear")
>
>   completeDate = mnuDay & "/" & mnuMonth & "/" & mnuYear
>
>   MM_editConnection = MM_connMtm_STRING
>   MM_editTable = "CUSTOMERS"
>   MM_editRedirectUrl = "confirm.asp"
>   MM_fieldsStr  = "completeDate|value"
>   MM_columnsStr = "DATEOFTRAVEL|#,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 i = LBound(MM_fields) To UBound(MM_fields) Step 2
>     MM_fields(i+1) = CStr(Request.Form(MM_fields(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
>
> If (CStr(Request("MM_insert")) <> "") Then
>
>   ' create the sql insert statement
>   MM_tableValues = ""
>   MM_dbValues = ""
>   For i = LBound(MM_fields) To UBound(MM_fields) Step 2
>     FormVal = MM_fields(i+1)
>     MM_typeArray = Split(MM_columns(i+1),",")
>     Delim = MM_typeArray(0)
>     If (Delim = "none") Then Delim = ""
>     AltVal = MM_typeArray(1)
>     If (AltVal = "none") Then AltVal = ""
>     EmptyVal = MM_typeArray(2)
>     If (EmptyVal = "none") Then EmptyVal = ""
>     If (FormVal = "") Then
>       FormVal = EmptyVal
>     Else
>       If (AltVal <> "") Then
>         FormVal = AltVal
>       ElseIf (Delim = "'") Then  ' escape quotes
>         FormVal = "'" & Replace(FormVal,"'","''") & "'"
>       Else
>         FormVal = Delim + FormVal + Delim
>       End If
>     End If
>     If (i <> LBound(MM_fields)) Then
>       MM_tableValues = MM_tableValues & ","
>       MM_dbValues = MM_dbValues & ","
>     End if
>     MM_tableValues = MM_tableValues & MM_columns(i)
>     MM_dbValues = MM_dbValues & 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
> %>
> <html>
> <head>
> <title>Untitled Document</title>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
> </head>
>
> <body bgcolor="#FFFFFF" text="#000000">
> <form name="insertDate" method="POST" action="<%=MM_editAction%>">
> <table border="0" cellspacing="3" cellpadding="0">
> <tr>
> <td class="mtmBody">
> <select name="mnuDay">
> <option value="no choice" selected>no choice</option>
> <option value="01">01</option>
> </select>
> </td>
> <td class="mtmBody">
> <select name="mnuMonth">
> <option value="no choice" selected>no choice</option>
> <option value="01">01</option>
> </select>
> </td>
> <td class="mtmBody">
> <select name="mnuYear">
> <option value="no choice" selected>no choice</option>
> <option value="2000">2000</option>
> </select>
> </td>
> <td class="mtmBody">
> <input type="submit" name="Submit" value="Submit">
> </td>
> </tr>
> </table>
> <input type="hidden" name="MM_insert" value="true">
> </form>
> </body>
> </html>
>
>


  Return to Index