sagelike
asked on
Type mismatch: 'LBound' problem in asp/access database configuration
I'm try to building a form that will post data to an access database using asp code and I'm getting an type mismatch lbound error:
Type mismatch: 'LBound'
/admin/inc_add.asp, line 107
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
I've checked the variable names and everything appears to match. Here's the code:
<!--#include file="../Connections/connD irectoryAd min.asp" -->
<%
' *** Restrict Access To Page: Grant or deny access to this page
MM_authorizedUsers=""
MM_authFailedURL="default. asp"
MM_grantAccess=false
If Session("MM_Username") <> "" Then
If (true Or CStr(Session("MM_UserAutho rization") )="") Or _
(InStr(1,MM_authorizedUser s,Session( "MM_UserAu thorizatio n"))>=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("U RL")
if (Len(Request.QueryString() ) > 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString()
MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referr er)
Response.Redirect(MM_authF ailedURL)
End If
%>
<%
' *** 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.ServerVariabl es("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") ) = "submit") Then
MM_editConnection = MM_connDirectory_STRING
MM_editTable = "DIRECTORY"
MM_editRedirectUrl = "viewRequests.asp"
MM_fieldsStr = "DIR_TYPE|value|Completed_ By|value|D ate_Submit ted|value| HSE_Yes|va lue|Referr ed_Date_HS E|value|HS E_Comment| value|HSE_ Response_Y es|value|H SE_Receive d|value|PE _Yes_No|va lue|Referr ed Date_PE|value|PE_Comment|v alue|PE_Re sponse|val ue|PE_Rece ived"
MM_columnsStr = "DIR_TYPE|none,none,NULL|C ompleted_B y|',none,' '|Date_Sub mitted|',n one,''|HSE _Yes|',non e,''|Refer red_Date_H SE|',none, ''|HSE_Com ment|',non e,''|HSE_R esponse_Ye s|',none,' '|HSE_Rece ived|',non e,''|PE_Ye s_No|',non e,''|Refer red_Date_P E|',none,' '|PE_Comme nt|',none, ''|PE_Resp onse|',non e,''|PE_Re ceived|',n one,''"
' 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_field s(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.ActiveConnectio n = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnectio n.Close
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editR edirectUrl )
End If
End If
End If
%>
<%
Dim rsType
Dim rsType_numRows
Set rsType = Server.CreateObject("ADODB .Recordset ")
rsType.ActiveConnection = MM_connDirectory_STRING
rsType.Source = "SELECT * FROM TYPE ORDER BY TYPE_NAME ASC"
rsType.CursorType = 0
rsType.CursorLocation = 2
rsType.LockType = 1
rsType.Open()
rsType_numRows = 0
%>
<script runat=SERVER language=VBSCRIPT>
function DoTrimProperly(str, nNamedFormat, properly, pointed, points)
dim strRet
strRet = Server.HTMLEncode(str)
strRet = replace(strRet, vbcrlf,"")
strRet = replace(strRet, vbtab,"")
If (LEN(strRet) > nNamedFormat) Then
strRet = LEFT(strRet, nNamedFormat)
If (properly = 1) Then
Dim TempArray
TempArray = split(strRet, " ")
Dim n
strRet = ""
for n = 0 to Ubound(TempArray) - 1
strRet = strRet & " " & TempArray(n)
next
End If
If (pointed = 1) Then
strRet = strRet & points
End If
End If
DoTrimProperly = strRet
End Function
</script>
<script language="JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&p arent.fram es.length) {
d=parent.frames[n.substrin g(p+1)].do cument; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length; i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d. layers.len gth;i++) x=MM_findObj(n,d.layers[i] .document) ;
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
//-->
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="text">
<tr>
<td align="left" valign="top"> <table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<form action="<%=MM_editAction%> " method="POST" name="form1" id="form1">
<td align="left" valign="top"><table class="text" width="800" cellpadding="2" cellspacing="0">
<tr>
<td nowrap="nowrap" align="right" valign="middle"><select name="DIR_TYPE">
<%
While (NOT rsType.EOF)
%>
<option value="<%=(rsType.Fields.I tem("TYPE_ ID").value )%>" ><%=(rsType.Fields.Item("T YPE_NAME") .Value)%>< /option>
<%
rsType.MoveNext()
Wend
If (rsType.CursorType > 0) Then
rsType.MoveFirst
Else
rsType.Requery
End If
%>
</select></td>
<td align="right" valign="middle" nowrap="nowrap"> </td >
<td colspan="4" align="right" valign="middle" nowrap="nowrap"><table class="text" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="right">Form Completed By:</div></td>
<th align="left" nowrap="nowrap"> </th >
<th align="left" nowrap="nowrap"><input name="Completed_By" type="text" id="Completed_By" size="30" /></th>
</tr>
<tr>
<td><div align="right">Date:</div>< /td>
<td> </td>
<td><input name="Date_Submitted" type="text" id="Date_Submitted" size="12" />
[ M/D/Y] </td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td nowrap="nowrap" align="right" valign="middle"> </td >
<td align="right" valign="middle" nowrap="nowrap"> </td >
<td nowrap="nowrap" valign="bottom">Referred Out Date </td>
<td valign="bottom">Comments / Approval<br />
Due Date </td>
<td valign="bottom">Response</ td>
<td valign="bottom">Rec'd</td>
</tr>
<tr>
<td height="1"><img src="assets/_spacer.gif" width="1" height="1" hspace="0" vspace="0" border="0" /></td>
<td height="1"><img src="assets/_spacer.gif" width="1" height="1" hspace="0" vspace="0" border="0" /></td>
<td height="1" colspan="4"><img src="assets/blackdot.gif" width="530" height="1" /></td>
</tr>
<tr>
<td align="right" nowrap="nowrap">HSE:</td>
<td align="center" nowrap>
<input type="radio" name="HSE_Yes" value="Yes" />Yes
<input type="radio" name="HSE_Yes" value="No" />No </td>
<td nowrap="nowrap"><input name="Referred_Date_HSE" type="text" id="Referred_Date_HSE" /></td>
<td><input name="HSE_Comment" type="text" id="HSE_Comment" /></td>
<td nowrap="nowrap">
<input type="radio" name="HSE_Response_Yes" value="Yes" />Yes
<input type="radio" name="HSE_Response_Yes" value="No" />No</td>
<td valign="middle"><input name="HSE_Received" type="text" id="HSE_Received" size="12" /></td>
</tr>
<tr>
<td align="right" nowrap="nowrap">Production Eng.: </td>
<td align="center" nowrap="nowrap">
<input type="radio" name="PE_Yes_No" value="Yes" />Yes
<input type="radio" name="PE_Yes_No" value="No" />No
</td>
<td nowrap="nowrap"><input name="Referred_Date_PE" type="text" id="Referred_Date_PE" /></td>
<td><input name="PE_Comment" type="text" id="PE_Comment" /></td>
<td>
<input type="radio" name="PE_Response" value="Yes" />Yes
<input type="radio" name="PE_Response" value="No" />No</td>
<td valign="middle"><input name="PE_Received" type="text" id="PE_Received" size="12" /></td>
</tr>
<tr>
<td align="right" nowrap="nowrap"> </td >
<td nowrap="nowrap"> </td >
<td colspan="2" nowrap="nowrap"><input name="submit" type="submit" value="Submit Change Request" /></td>
<td nowrap="nowrap"> </td >
<td nowrap="nowrap"> </td >
</tr>
</table></td>
<input type="hidden" name="MM_insert" value="form1">
</form>
</tr>
</table>
</td>
</tr>
</table>
<%
rsType.Close()
%>
--------
Here are the variable names in the access db:
Completed_By
Date_Submitted
HSE_Yes_No
Referred_Date_HSE
HSE_Comment
HSE_Response_Yes_No
HSE_Received
PE_Yes_No
Referred Date_PE
PE_Comment
PE_Response
PE_Received
I plan to add more fields however I can't move forward until I get this problem figured out and I'm not sure if it's a field naming problem. Hopefully you can help!
Thanks
Glenn
Type mismatch: 'LBound'
/admin/inc_add.asp, line 107
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
I've checked the variable names and everything appears to match. Here's the code:
<!--#include file="../Connections/connD
<%
' *** Restrict Access To Page: Grant or deny access to this page
MM_authorizedUsers=""
MM_authFailedURL="default.
MM_grantAccess=false
If Session("MM_Username") <> "" Then
If (true Or CStr(Session("MM_UserAutho
(InStr(1,MM_authorizedUser
MM_grantAccess = true
End If
End If
If Not MM_grantAccess Then
MM_qsChar = "?"
If (InStr(1,MM_authFailedURL,
MM_referrer = Request.ServerVariables("U
if (Len(Request.QueryString()
MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referr
Response.Redirect(MM_authF
End If
%>
<%
' *** 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.ServerVariabl
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")
MM_editConnection = MM_connDirectory_STRING
MM_editTable = "DIRECTORY"
MM_editRedirectUrl = "viewRequests.asp"
MM_fieldsStr = "DIR_TYPE|value|Completed_
MM_columnsStr = "DIR_TYPE|none,none,NULL|C
' 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_field
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")
' 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
MM_editCmd.ActiveConnectio
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnectio
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editR
End If
End If
End If
%>
<%
Dim rsType
Dim rsType_numRows
Set rsType = Server.CreateObject("ADODB
rsType.ActiveConnection = MM_connDirectory_STRING
rsType.Source = "SELECT * FROM TYPE ORDER BY TYPE_NAME ASC"
rsType.CursorType = 0
rsType.CursorLocation = 2
rsType.LockType = 1
rsType.Open()
rsType_numRows = 0
%>
<script runat=SERVER language=VBSCRIPT>
function DoTrimProperly(str, nNamedFormat, properly, pointed, points)
dim strRet
strRet = Server.HTMLEncode(str)
strRet = replace(strRet, vbcrlf,"")
strRet = replace(strRet, vbtab,"")
If (LEN(strRet) > nNamedFormat) Then
strRet = LEFT(strRet, nNamedFormat)
If (properly = 1) Then
Dim TempArray
TempArray = split(strRet, " ")
Dim n
strRet = ""
for n = 0 to Ubound(TempArray) - 1
strRet = strRet & " " & TempArray(n)
next
End If
If (pointed = 1) Then
strRet = strRet & points
End If
End If
DoTrimProperly = strRet
End Function
</script>
<script language="JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&p
d=parent.frames[n.substrin
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;
for(i=0;!x&&d.layers&&i<d.
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
//-->
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="text">
<tr>
<td align="left" valign="top"> <table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<form action="<%=MM_editAction%>
<td align="left" valign="top"><table class="text" width="800" cellpadding="2" cellspacing="0">
<tr>
<td nowrap="nowrap" align="right" valign="middle"><select name="DIR_TYPE">
<%
While (NOT rsType.EOF)
%>
<option value="<%=(rsType.Fields.I
<%
rsType.MoveNext()
Wend
If (rsType.CursorType > 0) Then
rsType.MoveFirst
Else
rsType.Requery
End If
%>
</select></td>
<td align="right" valign="middle" nowrap="nowrap"> </td
<td colspan="4" align="right" valign="middle" nowrap="nowrap"><table class="text" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="right">Form Completed By:</div></td>
<th align="left" nowrap="nowrap"> </th
<th align="left" nowrap="nowrap"><input name="Completed_By" type="text" id="Completed_By" size="30" /></th>
</tr>
<tr>
<td><div align="right">Date:</div><
<td> </td>
<td><input name="Date_Submitted" type="text" id="Date_Submitted" size="12" />
[ M/D/Y] </td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td nowrap="nowrap" align="right" valign="middle"> </td
<td align="right" valign="middle" nowrap="nowrap"> </td
<td nowrap="nowrap" valign="bottom">Referred Out Date </td>
<td valign="bottom">Comments / Approval<br />
Due Date </td>
<td valign="bottom">Response</
<td valign="bottom">Rec'd</td>
</tr>
<tr>
<td height="1"><img src="assets/_spacer.gif" width="1" height="1" hspace="0" vspace="0" border="0" /></td>
<td height="1"><img src="assets/_spacer.gif" width="1" height="1" hspace="0" vspace="0" border="0" /></td>
<td height="1" colspan="4"><img src="assets/blackdot.gif" width="530" height="1" /></td>
</tr>
<tr>
<td align="right" nowrap="nowrap">HSE:</td>
<td align="center" nowrap>
<input type="radio" name="HSE_Yes" value="Yes" />Yes
<input type="radio" name="HSE_Yes" value="No" />No </td>
<td nowrap="nowrap"><input name="Referred_Date_HSE" type="text" id="Referred_Date_HSE" /></td>
<td><input name="HSE_Comment" type="text" id="HSE_Comment" /></td>
<td nowrap="nowrap">
<input type="radio" name="HSE_Response_Yes" value="Yes" />Yes
<input type="radio" name="HSE_Response_Yes" value="No" />No</td>
<td valign="middle"><input name="HSE_Received" type="text" id="HSE_Received" size="12" /></td>
</tr>
<tr>
<td align="right" nowrap="nowrap">Production
<td align="center" nowrap="nowrap">
<input type="radio" name="PE_Yes_No" value="Yes" />Yes
<input type="radio" name="PE_Yes_No" value="No" />No
</td>
<td nowrap="nowrap"><input name="Referred_Date_PE" type="text" id="Referred_Date_PE" /></td>
<td><input name="PE_Comment" type="text" id="PE_Comment" /></td>
<td>
<input type="radio" name="PE_Response" value="Yes" />Yes
<input type="radio" name="PE_Response" value="No" />No</td>
<td valign="middle"><input name="PE_Received" type="text" id="PE_Received" size="12" /></td>
</tr>
<tr>
<td align="right" nowrap="nowrap"> </td
<td nowrap="nowrap"> </td
<td colspan="2" nowrap="nowrap"><input name="submit" type="submit" value="Submit Change Request" /></td>
<td nowrap="nowrap"> </td
<td nowrap="nowrap"> </td
</tr>
</table></td>
<input type="hidden" name="MM_insert" value="form1">
</form>
</tr>
</table>
</td>
</tr>
</table>
<%
rsType.Close()
%>
--------
Here are the variable names in the access db:
Completed_By
Date_Submitted
HSE_Yes_No
Referred_Date_HSE
HSE_Comment
HSE_Response_Yes_No
HSE_Received
PE_Yes_No
Referred Date_PE
PE_Comment
PE_Response
PE_Received
I plan to add more fields however I can't move forward until I get this problem figured out and I'm not sure if it's a field naming problem. Hopefully you can help!
Thanks
Glenn
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the quick reply. I tried your solution but it generated a different error. Progress of sorts because I 've been looking at the same error all night.
This is what I'm getting now:
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
/admin/inc_add.asp, line 140
Does that help narrow the problem down a little?
THanks
Glenn