troubleshooting Question

Type mismatch: 'LBound' problem in asp/access database configuration

Avatar of sagelike
sagelike asked on
Microsoft AccessASPMicrosoft IIS Web Server
3 Comments1 Solution648 ViewsLast Modified:
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/connDirectoryAdmin.asp" -->

' *** Restrict Access To Page: Grant or deny access to this page
If Session("MM_Username") <> "" Then
  If (true 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)
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.ServerVariables("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|Date_Submitted|value|HSE_Yes|value|Referred_Date_HSE|value|HSE_Comment|value|HSE_Response_Yes|value|HSE_Received|value|PE_Yes_No|value|Referred Date_PE|value|PE_Comment|value|PE_Response|value|PE_Received"
  MM_columnsStr = "DIR_TYPE|none,none,NULL|Completed_By|',none,''|Date_Submitted|',none,''|HSE_Yes|',none,''|Referred_Date_HSE|',none,''|HSE_Comment|',none,''|HSE_Response_Yes|',none,''|HSE_Received|',none,''|PE_Yes_No|',none,''|Referred_Date_PE|',none,''|PE_Comment|',none,''|PE_Response|',none,''|PE_Received|',none,''"

   ' 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)))

  ' 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
      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
      If (MM_altVal <> "") Then
        MM_formVal = MM_altVal
      ElseIf (MM_delim = "'") Then  ' escape quotes
        MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
        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
  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

    If (MM_editRedirectUrl <> "") Then
    End If
  End If

End If
Dim rsType
Dim rsType_numRows

Set rsType = Server.CreateObject("ADODB.Recordset")
rsType.ActiveConnection = MM_connDirectory_STRING
rsType.CursorType = 0
rsType.CursorLocation = 2
rsType.LockType = 1

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)
    End If
    If (pointed = 1) Then
      strRet = strRet & points
    End If
  End If
  DoTrimProperly = strRet
End Function

<script language="JavaScript">

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; 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.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;


  <table width="100%" border="0" cellspacing="0" cellpadding="0" class="text">
      <td align="left" valign="top"> <table width="100%" border="0" cellspacing="2" cellpadding="2">
          <form action="<%=MM_editAction%>" method="POST" name="form1" id="form1">
            <td align="left" valign="top"><table class="text" width="800" cellpadding="2" cellspacing="0">
                <td nowrap="nowrap" align="right" valign="middle"><select name="DIR_TYPE">
While (NOT rsType.EOF)
          <option value="<%=(rsType.Fields.Item("TYPE_ID").value)%>" ><%=(rsType.Fields.Item("TYPE_NAME").Value)%></option>
If (rsType.CursorType > 0) Then
End If
                <td align="right" valign="middle" nowrap="nowrap">&nbsp;</td>
                <td colspan="4" align="right" valign="middle" nowrap="nowrap"><table class="text" width="100%" border="0" cellspacing="0" cellpadding="0">
                      <td><div align="right">Form Completed By:</div></td>
                      <th align="left" nowrap="nowrap">&nbsp;</th>
                      <th align="left" nowrap="nowrap"><input name="Completed_By" type="text" id="Completed_By" size="30" /></th>
                      <td><div align="right">Date:</div></td>
                      <td><input name="Date_Submitted" type="text" id="Date_Submitted" size="12" />
[ M/D/Y] </td>
                <td nowrap="nowrap" align="right" valign="middle">&nbsp;</td>
                <td align="right" valign="middle" nowrap="nowrap">&nbsp;</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>
                <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>
                <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>

                <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 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>
                  <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>
                <td align="right" nowrap="nowrap">&nbsp;</td>
                <td nowrap="nowrap">&nbsp;</td>
                <td colspan="2" nowrap="nowrap"><input name="submit" type="submit" value="Submit Change Request" /></td>
                <td nowrap="nowrap">&nbsp;</td>
                <td nowrap="nowrap">&nbsp;</td>
            <input type="hidden" name="MM_insert" value="form1">



Here are the variable names in the access db:

Referred Date_PE

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!

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros