Get ready for BLACK FRIDAY shopping starting in

Forums

This topic is locked

Problem with insert record.

Posted 11 Oct 2006 21:30:40
1
has voted
11 Oct 2006 21:30:40 jack fairchild posted:
I am using the DW insert record application object. It successfully enters a record into the table, but will not enter a second. The error says you can have no duplicates in the primary key. Since I only have the one record in it I KNOW I am not duplicating the key. If I delete the record from access I can enter another, but once there is one in there it will not add another. Help!!!

DWMX / ASP / ACCESS

Here is the code.

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../Connections/ACCESSDBASE.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_ACCESSDBASE_STRING
MM_editTable = "tblContractEstimate"
MM_editRedirectUrl = "../Pages/Home.html"
MM_fieldsStr = "EstimateNum|value|JobNum|value|CompanyName|value|JobName|value|JobStreetAddress|value|JobCounty|value|JobCity|value|JobState|value|JobZipcode|value|BidStatus|value|Plans|value|Spec|value|Survey|value|LightwallPipe|value|WeldedOutlets|value|EstimatePlan|value|NewConstruction|value|ExistingBuilding|value|ExistingSystem|value|PlansSubmittedBy|value|Sleeves|value|COT|value|PESeal|value|Phased|value|Cad|value|CadFee|value|CadAvailablefrom|value|Estimator|value|BidDate|value|BidTime|value|StartDate|value|FinishDate|value|LiquidatedDamages|value|BuyAmerican|value|HeadCount|value|Underground|value|SprinklerTypes|value|Hazard|value|ConstructionType|value|AltAccepted|value|WhichAlternates|value|AddendumNum|value|Notes|value|Specials|value|PointOfConnection|value|TaxExempt|value|PrevailingWage|value|PermitsByUs|value|QuoteNum|value|SteelCertification|value"
MM_columnsStr = "EstimateNum|',none,''|JobNum|',none,''|CompanyName|',none,''|JobName|',none,''|JobStreetAddress|',none,''|JobCounty|',none,''|JobCity|',none,''|JobState|',none,''|JobZipcode|',none,''|BidStatus|',none,''|Plans|none,1,0|Spec|none,1,0|Survey|none,1,0|LightwallPipe|none,1,0|WeldedOutlets|none,1,0|EstimatePlan|none,1,0|NewConstruction|none,1,0|ExistingBuilding|none,1,0|ExistingSystem|none,1,0|PlansSubmittedBy|',none,''|Sleeves|none,1,0|COT|none,1,0|PESeal|none,1,0|Phased|none,1,0|Cad|none,1,0|CadFee|none,1,0|CadAvailablefrom|',none,''|Estimator|',none,''|BidDate|',none,NULL|BidTime|',none,NULL|StartDate|',none,NULL|FinishDate|',none,NULL|LiquidatedDamages|none,1,0|BuyAmerican|none,1,0|HeadCount|none,none,NULL|Underground|none,1,0|SprinklerTypes|',none,''|Hazard|',none,''|ConstructionType|',none,''|AltAccepted|none,1,0|WhichAlternates|',none,''|AddendumNum|',none,''|Notes|',none,''|Specials|',none,''|PointOfConnection|',none,''|TaxExempt|none,1,0|PrevailingWage|none,1,0|PermitsByUs|none,1,0|QuoteNum|',none,''|SteelCertification|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
%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form action="<%=MM_editAction%>" method="post" name="form1">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">EstimateNum:</td>
<td><input type="text" name="EstimateNum" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">JobNum:</td>
<td><input type="text" name="JobNum" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">CompanyName:</td>
<td><input type="text" name="CompanyName" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">JobName:</td>
<td><input type="text" name="JobName" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">JobStreetAddress:</td>
<td><input type="text" name="JobStreetAddress" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">JobCounty:</td>
<td><input type="text" name="JobCounty" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">JobCity:</td>
<td><input type="text" name="JobCity" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">JobState:</td>
<td><input type="text" name="JobState" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">JobZipcode:</td>
<td><input type="text" name="JobZipcode" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">BidStatus:</td>
<td><input type="text" name="BidStatus" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Plans:</td>
<td><input type="checkbox" name="Plans" value=1 >
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Spec:</td>
<td><input type="checkbox" name="Spec" value=1 >
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Survey:</td>
<td><input type="checkbox" name="Survey" value=1 >
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">LightwallPipe:</td>
<td><input type="checkbox" name="LightwallPipe" value=1 >
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">WeldedOutlets:</td>
<td><input type="checkbox" name="WeldedOutlets" value=1 >
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">EstimatePlan:</td>
<td><input type="checkbox" name="EstimatePlan" value=1 >
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">NewConstruction:</td>
<td><input type="checkbox" name="NewConstruction" value=1 >
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">ExistingBuilding:</td>
<td><input type="checkbox" name="ExistingBuilding" value=1 >
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">ExistingSystem:</td>
<td><input type="checkbox" name="ExistingSystem" value=1 >
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">PlansSubmittedBy:</td>
<td><input type="text" name="PlansSubmittedBy" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Sleeves:</td>
<td><input type="checkbox" name="Sleeves" value=1 >
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">COT:</td>
<td><input type="checkbox" name="COT" value=1 >
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">PESeal:</td>
<td><input type="checkbox" name="PESeal" value=1 >
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Phased:</td>
<td><input type="checkbox" name="Phased" value=1 >
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Cad:</td>
<td><input type="checkbox" name="Cad" value=1 >
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">CadFee:</td>
<td><input type="checkbox" name="CadFee" value=1 >
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">CadAvailablefrom:</td>
<td><input type="text" name="CadAvailablefrom" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Estimator:</td>
<td><input type="text" name="Estimator" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">BidDate:</td>
<td><input type="text" name="BidDate" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">BidTime:</td>
<td><input type="text" name="BidTime" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">StartDate:</td>
<td><input type="text" name="StartDate" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">FinishDate:</td>
<td><input type="text" name="FinishDate" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">LiquidatedDamages:</td>
<td><input type="checkbox" name="LiquidatedDamages" value=1 >
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">BuyAmerican:</td>
<td><input type="checkbox" name="BuyAmerican" value=1 >
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">HeadCount:</td>
<td><input type="text" name="HeadCount" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Underground:</td>
<td><input type="checkbox" name="Underground" value=1 >
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">SprinklerTypes:</td>
<td><input type="text" name="SprinklerTypes" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Hazard:</td>
<td><input type="text" name="Hazard" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">ConstructionType:</td>
<td><input type="text" name="ConstructionType" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">AltAccepted:</td>
<td><input type="checkbox" name="AltAccepted" value=1 >
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">WhichAlternates:</td>
<td><input type="text" name="WhichAlternates" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">AddendumNum:</td>
<td><input type="text" name="AddendumNum" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Notes:</td>
<td><input type="text" name="Notes" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Specials:</td>
<td><input type="text" name="Specials" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">PointOfConnection:</td>
<td><input type="text" name="PointOfConnection" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">TaxExempt:</td>
<td><input type="checkbox" name="TaxExempt" value=1 >
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">PrevailingWage:</td>
<td><input type="checkbox" name="PrevailingWage" value=1 >
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">PermitsByUs:</td>
<td><input type="checkbox" name="PermitsByUs" value=1 >
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">QuoteNum:</td>
<td><input type="text" name="QuoteNum" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">SteelCertification:</td>
<td><input type="checkbox" name="SteelCertification" value=1 >
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Insert record">
</td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
<p> </p>
<p> </p>
</body>
</html>

Reply to this topic