troubleshooting Question

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

Avatar of sagelike
sagelike asked on
ASPMicrosoft IIS Web ServerMicrosoft Access
3 Comments2 Solutions648 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
MM_authorizedUsers=""
MM_authFailedURL="default.asp"
MM_grantAccess=false
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)
  Response.Redirect(MM_authFailedURL)
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)))
  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
%>
<%
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&&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;
}

//-->
</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.Item("TYPE_ID").value)%>" ><%=(rsType.Fields.Item("TYPE_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">&nbsp;</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">&nbsp;</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>&nbsp;</td>
                      <td><input name="Date_Submitted" type="text" id="Date_Submitted" size="12" />
[ M/D/Y] </td>
                    </tr>
                </table></td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <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>
              </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">&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>
              </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
kelvinwkw

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 2 Answers and 3 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 2 Answers and 3 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004