Forums
This topic is locked
Update then Pass URL parameter
Posted 08 Feb 2007 20:10:44
1
has voted
08 Feb 2007 20:10:44 Bryan McGuire posted:
I have a form that updates a SQL database correctly.I would like to pass a form field to the next page (when the submit button is selected).
Here is the error I get after adding + Inventory.Fields.Item("Room".Value to the following line
MM_editRedirectUrl = "InventorySelectItem.asp?room="
Microsoft VBScript runtime error '800a01a8'
Object required: ''
/InventoryView.asp, line 49
Please help, I am very new to this.
Here is the entire code for the page.
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/SPSData.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 = ""
%>
<%
' *** Update Record: set variables
If (CStr(Request("MM_update") = "form1" And CStr(Request("MM_recordId") <> "" Then
MM_editConnection = MM_SPSData_STRING
MM_editTable = "dbo.Inventory"
MM_editColumn = "ID"
MM_recordId = "" + Request.Form("MM_recordId" + ""
MM_editRedirectUrl = "InventorySelectItem.asp?room=" + Inventory.Fields.Item("Room".Value
MM_fieldsStr = "Building|value|Room|value|Teacher|value|Item|value|Quantity|value|Condition|value|Description|value|Date|value"
MM_columnsStr = "Building|',none,''|Room|',none,''|Teacher|',none,''|Item|',none,''|Quantity|',none,''|Condition|',none,''|Description|',none,''|Date|',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
%>
<%
' *** Update Record: construct a sql update statement and execute it
If (CStr(Request("MM_update") <> "" And CStr(Request("MM_recordId") <> "" Then
' create the sql update statement
MM_editQuery = "update " & MM_editTable & " set "
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_editQuery = MM_editQuery & ","
End If
MM_editQuery = MM_editQuery & MM_columns(MM_i) & " = " & MM_formVal
Next
MM_editQuery = MM_editQuery & " where " & MM_editColumn & " = " & MM_recordId
If (Not MM_abortEdit) Then
' execute the update
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
%>
<%
' *** Restrict Access To Page: Grant or deny access to this page
MM_authorizedUsers="A"
MM_authFailedURL="login.asp"
MM_grantAccess=false
If Session("MM_Username" <> "" Then
If (false Or CStr(Session("MM_UserAuthorization")="" Or _
(InStr(1,MM_authorizedUsers,Session("MM_UserAuthorization")>=1) Then
MM_grantAccess = true
End If
End If
If Not MM_grantAccess Then
MM_qsChar = "?"
If (InStr(1,MM_authFailedURL,"?" >= 1) Then MM_qsChar = "&"
MM_referrer = Request.ServerVariables("URL"
if (Len(Request.QueryString()) > 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString()
MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referrer)
Response.Redirect(MM_authFailedURL)
End If
%>
<%
Dim Inventory__MMColParam
Inventory__MMColParam = "1"
If (Request.QueryString("ID" <> "" Then
Inventory__MMColParam = Request.QueryString("ID"
End If
%>
<%
Dim Inventory
Dim Inventory_numRows
Set Inventory = Server.CreateObject("ADODB.Recordset"
Inventory.ActiveConnection = MM_SPSData_STRING
Inventory.Source = "SELECT * FROM dbo.Inventory WHERE ID = " + Replace(Inventory__MMColParam, "'", "''" + " ORDER BY Item ASC"
Inventory.CursorType = 0
Inventory.CursorLocation = 2
Inventory.LockType = 1
Inventory.Open()
Inventory_numRows = 0
%>
<%
Dim Building
Dim Building_numRows
Set Building = Server.CreateObject("ADODB.Recordset"
Building.ActiveConnection = MM_SPSData_STRING
Building.Source = "SELECT * FROM dbo.Buildings"
Building.CursorType = 0
Building.CursorLocation = 2
Building.LockType = 1
Building.Open()
Building_numRows = 0
%>
<%
Dim Room
Dim Room_numRows
Set Room = Server.CreateObject("ADODB.Recordset"
Room.ActiveConnection = MM_SPSData_STRING
Room.Source = "SELECT * FROM dbo.RoomNumbers"
Room.CursorType = 0
Room.CursorLocation = 2
Room.LockType = 1
Room.Open()
Room_numRows = 0
%>
<%
Dim User
Dim User_numRows
Set User = Server.CreateObject("ADODB.Recordset"
User.ActiveConnection = MM_SPSData_STRING
User.Source = "SELECT * FROM dbo.Users"
User.CursorType = 0
User.CursorLocation = 2
User.LockType = 1
User.Open()
User_numRows = 0
%>
<%
Dim Condition
Dim Condition_numRows
Set Condition = Server.CreateObject("ADODB.Recordset"
Condition.ActiveConnection = MM_SPSData_STRING
Condition.Source = "SELECT * FROM dbo.Condition"
Condition.CursorType = 0
Condition.CursorLocation = 2
Condition.LockType = 1
Condition.Open()
Condition_numRows = 0
%>
<%
Dim Item
Dim Item_numRows
Set Item = Server.CreateObject("ADODB.Recordset"
Item.ActiveConnection = MM_SPSData_STRING
Item.Source = "SELECT * FROM dbo.Items"
Item.CursorType = 0
Item.CursorLocation = 2
Item.LockType = 1
Item.Open()
Item_numRows = 0
%>
<!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>Inventory View Item</title>
<style type="text/css">
<!--
.style1 {
font-size: 18px;
font-weight: bold;
}
.style2 {font-size: 12px}
.style3 {font-size: 12px; font-weight: bold; }
.style4 {color: #000000}
.style5 {font-size: 12px; font-weight: bold; color: #000000; }
-->
</style>
</head>
<body>
<table width="84%" border="0" align="center">
<tr>
<td><div align="center"><span class="style1">Inventory Edit / Create New </span></div></td>
</tr>
<tr>
<td class="style3"><div align="center"></div></td>
</tr>
</table>
<form method="POST" action="<%=MM_editAction%>" name="form1">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">ID:</td>
<td><input type="text" name="ID" value="<%=(Inventory.Fields.Item("ID".Value)%>" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Building:</td>
<td><select name="Building">
<option value="<%= Inventory.Fields.Item("Building".Value %>" <%If (Not isNull(Inventory.Fields.Item("Building".Value)) Then If (Inventory.Fields.Item("Building".Value = CStr(Inventory.Fields.Item("Building".Value)) Then Response.Write("SELECTED" : Response.Write(""%>><%= Inventory.Fields.Item("Building".Value %></option>
<%
While (NOT Building.EOF)
%>
<option value="<%=(Building.Fields.Item("Building".Value)%>" <%If (Not isNull(Inventory.Fields.Item("Building".Value)) Then If (CStr(Building.Fields.Item("Building".Value) = CStr(Inventory.Fields.Item("Building".Value)) Then Response.Write("SELECTED" : Response.Write(""%> ><%=(Building.Fields.Item("Building".Value)%></option>
<%
Building.MoveNext()
Wend
If (Building.CursorType > 0) Then
Building.MoveFirst
Else
Building.Requery
End If
%>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Room:</td>
<td><select name="Room">
<option value="<%=(Room.Fields.Item("roomNumber".Value)%>" <%If (Not isNull(Inventory.Fields.Item("Room".Value)) Then If (CStr(Room.Fields.Item("roomNumber".Value) = CStr(Inventory.Fields.Item("Room".Value)) Then Response.Write("SELECTED" : Response.Write(""%> ><%=(Room.Fields.Item("roomNumber".Value)%></option>
<%
While (NOT Room.EOF)
%>
<option value="<%=(Room.Fields.Item("roomNumber".Value)%>" <%If (Not isNull(Inventory.Fields.Item("Room".Value)) Then If (CStr(Room.Fields.Item("roomNumber".Value) = CStr(Inventory.Fields.Item("Room".Value)) Then Response.Write("SELECTED" : Response.Write(""%> ><%=(Room.Fields.Item("roomNumber".Value)%></option>
<%
Room.MoveNext()
Wend
If (Room.CursorType > 0) Then
Room.MoveFirst
Else
Room.Requery
End If
%>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Teacher:</td>
<td><select name="Teacher">
<option value="<%= Inventory.Fields.Item("Teacher".Value %>" <%If (Not isNull(Inventory.Fields.Item("Teacher".Value)) Then If (Inventory.Fields.Item("Teacher".Value = CStr(Inventory.Fields.Item("Teacher".Value)) Then Response.Write("SELECTED" : Response.Write(""%>><%= Inventory.Fields.Item("Teacher".Value %></option>
<%
While (NOT User.EOF)
%>
<option value="<%=(User.Fields.Item("users".Value)%>" <%If (Not isNull(Inventory.Fields.Item("Teacher".Value)) Then If (CStr(User.Fields.Item("users".Value) = CStr(Inventory.Fields.Item("Teacher".Value)) Then Response.Write("SELECTED" : Response.Write(""%> ><%=(User.Fields.Item("users".Value)%></option>
<%
User.MoveNext()
Wend
If (User.CursorType > 0) Then
User.MoveFirst
Else
User.Requery
End If
%>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Item:</td>
<td><select name="Item">
<option value="<%= Inventory.Fields.Item("Item".Value %>" <%If (Not isNull(Inventory.Fields.Item("Item".Value)) Then If (Inventory.Fields.Item("Item".Value = CStr(Inventory.Fields.Item("Item".Value)) Then Response.Write("SELECTED" : Response.Write(""%>><%= Inventory.Fields.Item("Item".Value %></option>
<%
While (NOT Item.EOF)
%>
<option value="<%=(Item.Fields.Item("Item".Value)%>" <%If (Not isNull(Inventory.Fields.Item("Item".Value)) Then If (CStr(Item.Fields.Item("Item".Value) = CStr(Inventory.Fields.Item("Item".Value)) Then Response.Write("SELECTED" : Response.Write(""%> ><%=(Item.Fields.Item("Item".Value)%></option>
<%
Item.MoveNext()
Wend
If (Item.CursorType > 0) Then
Item.MoveFirst
Else
Item.Requery
End If
%>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Quantity:</td>
<td><input type="text" name="Quantity" value="<%=(Inventory.Fields.Item("Quantity".Value)%>" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Condition:</td>
<td><select name="Condition">
<option value="<%= Inventory.Fields.Item("Condition".Value %>" <%If (Not isNull(Inventory.Fields.Item("Condition".Value)) Then If (Inventory.Fields.Item("Condition".Value = CStr(Inventory.Fields.Item("Condition".Value)) Then Response.Write("SELECTED" : Response.Write(""%>><%= Inventory.Fields.Item("Condition".Value %></option>
<%
While (NOT Inventory.EOF)
%>
<option value="<%=(Inventory.Fields.Item("Condition".Value)%>" <%If (Not isNull(Inventory.Fields.Item("Condition".Value)) Then If (CStr(Inventory.Fields.Item("Condition".Value) = CStr(Inventory.Fields.Item("Condition".Value)) Then Response.Write("SELECTED" : Response.Write(""%> ><%=(Inventory.Fields.Item("Condition".Value)%></option>
<%
Inventory.MoveNext()
Wend
If (Inventory.CursorType > 0) Then
Inventory.MoveFirst
Else
Inventory.Requery
End If
%>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Description:</td>
<td><input type="text" name="Description" value="<%=(Inventory.Fields.Item("Description".Value)%>" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Date:</td>
<td><input type="text" name="Date" value="<%=(Inventory.Fields.Item("Date".Value)%>" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Update record">
</td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="MM_recordId" value="<%= Inventory.Fields.Item("ID".Value %>">
</form>
<p> </p>
</body>
</html>
<%
Inventory.Close()
Set Inventory = Nothing
%>
<%
Building.Close()
Set Building = Nothing
%>
<%
Room.Close()
Set Room = Nothing
%>
<%
User.Close()
Set User = Nothing
%>
<%
Condition.Close()
Set Condition = Nothing
%>
<%
Item.Close()
Set Item = Nothing
%>