p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

access thread: Problem with my code...


Message #1 by "Robert Harrigan" <rharrigan@f...> on Fri, 7 Jun 2002 11:06:15 -0400
This is a multi-part message in MIME format.

------=_NextPart_000_0001_01C20E13.57F53390
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

I created a database a while back and it works great.  I am now making a
new database and I am having problems.  The .asp file that processes the
code works to add new items to the Access database and to remove items
from the database.  However, when I try to modify items in the database
I get the following error:
 
Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'objConn'
/po/TradingPost/Trade_Processor.asp, line 342
 
Does anyone have any tips to get me over this hump?
 
Thanks!
Robert
rharrigan@f...
 
************* Here is my code (Line 342 is marked below at the very end)
***************
 
<%
'Declare variables needed
Dim strInsert
Dim strValues
Dim strSQL
Dim adCmdText
Dim blnCriticalError
Dim blnFirstParameter
 
'Set required variables
adCmdText = 1
            
'*************************************************************
'* If an Add was requested, add a new trade to the database
'*************************************************************
If Request.Form("Action") = "Add" Then
 
            'Start building the SQL strings with the required fields
            strInsert = "Insert into Items (FName,LName"
            strValues = "Values('" & CStr(Request.Form("fname")) & _
                        "','" & CStr(Request.Form("lname")) & "'"
 
            
                                    *********** Add Statements Here
***********
 
            'Create and open the database object
            Set objConn = Server.CreateObject("ADODB.Connection")
            objConn.Open "DSN=Trade"
 
            'Create the command object
            Set objCmd = Server.CreateObject("ADODB.Command")
 
            'Set the command object properties
            Set objCmd.ActiveConnection = objConn
            objCmd.CommandText = strInsert & ") " & strValues & ")"
            objCmd.CommandType = adCmdText
 
            'Execute the command
            objCmd.Execute
                        
            'Display the insert string
            Response.Write "<b>Your ad will be verified and added to the
Trading Post by the next business day.</b>"
            
'*******************************************************************
'* If an Update was requested, update the trade in the database
'*******************************************************************
ElseIf Request.Form("Action") = "Update" Then
 
            'Start building the SQL string
            strSQL = "Update Items Set"
 
            'Set the first parameter flag to true
            blnFirstParameter = True
 
                                    *********** Update Statements Here
***********
 
            'Set the Where clause
            strSQL = strSQL & " Where Id = " & Request.Form("Selection")
& " "
 
            'Create and open the database object
            Set objConn = Server.CreateObject("ADODB.Connection")
            objConn.Open "DSN=Trade"
 
            'Create the command object
            Set objCmd = Server.CreateObject("ADODB.Command")
 
            'Set the command object properties
            Set objCmd.ActiveConnection = objConn
            objCmd.CommandText = strSQL
            objCmd.CommandType = adCmdText
 
            'Execute the command
            objCmd.Execute
 
            'Display the update string
            Response.Write "<center>The crewmember's information has
been <b>Updated</b> on the phone list.<br>"
            Response.Write "[ <a href='admin.asp'>Return To The
Administrator</a> ]</center>"
 
'**************************************************************
'* If a Delete was requested, delete the trade from the database
'**************************************************************
ElseIf Request.Form("Action") = "Delete" Then
 
            'Build the SQL string
            strSQL = "Delete * from Items Where Id = " &
Request.Form("Selection") & " "
            
            'Create and open the database object
            Set objConn = Server.CreateObject("ADODB.Connection")
            objConn.Open "DSN=Trade"
 
            'Create the command object
            Set objCmd = Server.CreateObject("ADODB.Command")
 
            'Set the command object properties
            Set objCmd.ActiveConnection = objConn
            objCmd.CommandText = strSQL
            objCmd.CommandType = adCmdText
 
            'Execute the command
            objCmd.Execute
 
            'Display the delete string
            Response.Write "<center>The Ad has been <b>Removed</b> from
the Trading Post.<br>"
            Response.Write "[ <a href='admin.asp'>Return To The
Administrator</a> ]</center>"
 
End If    'End If for step processing
 
'Close and dereference database objects
Set objCmd = Nothing
objConn.Close                                       <-- Line #342
Set objConn = Nothing
%>



Message #2 by "Wong Tze Lun" <tzelun0502@l...> on Fri, 07 Jun 2002 22:46:27 +0700
hi robert
 It seem like your connection to the database have been off . try to reconnect to the databse first before u running the updating or
u can test the connection state to see whether it is still alive or not 

regards
tl wong


_______________________________________________________
WIN a first class trip to Hawaii.  Live like the King of Rock and Roll
on the big Island. Enter Now!
http://r.lycos.com/r/sagel_mail/http://www.elvis.lycos.com/sweepstakes
Message #3 by "Leo Scott" <leoscott@c...> on Fri, 7 Jun 2002 09:05:27 -0700
This is a multi-part message in MIME format.

------=_NextPart_000_0026_01C20E02.771D2F40
Content-Type: text/plain;
	charset="Windows-1252"
Content-Transfer-Encoding: 8bit

if objConn.State = 1 then
   objConn.Close
end if

I used the number 1 because I don't think vbScript has access to ObjectStateEnum.

The other concern I would have is that none of your If conditions are evaluating to true when this error occurs and it
never opens the connection.



 -----Original Message-----
From: Robert Harrigan [mailto:rharrigan@f...]
Sent: Friday, June 07, 2002 8:06 AM
To: Access
Subject: [access] Problem with my code...


  I created a database a while back and it works great.  I am now making a new database and I am having problems.  The
.asp file that processes the code works to add new items to the Access database and to remove items from the database.
However, when I try to modify items in the database I get the following error:



  Error Type:
  Microsoft VBScript runtime (0x800A01A8)
  Object required: 'objConn'

  /po/TradingPost/Trade_Processor.asp, line 342



  Does anyone have any tips to get me over this hump?



  Thanks!

  Robert

  rharrigan@f...



  ************* Here is my code (Line 342 is marked below at the very end) ***************



  <%

  'Declare variables needed

  Dim strInsert

  Dim strValues

  Dim strSQL

  Dim adCmdText

  Dim blnCriticalError

  Dim blnFirstParameter



  'Set required variables

  adCmdText = 1



  '*************************************************************

  '* If an Add was requested, add a new trade to the database

  '*************************************************************

  If Request.Form("Action") = "Add" Then



              'Start building the SQL strings with the required fields

              strInsert = "Insert into Items (FName,LName"

              strValues = "Values('" & CStr(Request.Form("fname")) & _

                          "','" & CStr(Request.Form("lname")) & "'"





                                      *********** Add Statements Here ***********



              'Create and open the database object

              Set objConn = Server.CreateObject("ADODB.Connection")

              objConn.Open "DSN=Trade"



              'Create the command object

              Set objCmd = Server.CreateObject("ADODB.Command")



              'Set the command object properties

              Set objCmd.ActiveConnection = objConn

              objCmd.CommandText = strInsert & ") " & strValues & ")"

              objCmd.CommandType = adCmdText



              'Execute the command

              objCmd.Execute



              'Display the insert string

              Response.Write "<b>Your ad will be verified and added to the Trading Post by the next business day.</b>"



  '*******************************************************************

  '* If an Update was requested, update the trade in the database

  '*******************************************************************

  ElseIf Request.Form("Action") = "Update" Then



              'Start building the SQL string

              strSQL = "Update Items Set"



              'Set the first parameter flag to true

              blnFirstParameter = True



                                      *********** Update Statements Here ***********



              'Set the Where clause

              strSQL = strSQL & " Where Id = " & Request.Form("Selection") & " "



              'Create and open the database object

              Set objConn = Server.CreateObject("ADODB.Connection")

              objConn.Open "DSN=Trade"



              'Create the command object

              Set objCmd = Server.CreateObject("ADODB.Command")



              'Set the command object properties

              Set objCmd.ActiveConnection = objConn

              objCmd.CommandText = strSQL

              objCmd.CommandType = adCmdText



              'Execute the command

              objCmd.Execute



              'Display the update string

              Response.Write "<center>The crewmember's information has been <b>Updated</b> on the phone
list.<br>"

              Response.Write "[ <a href='admin.asp'>Return To The Administrator</a> ]</center>"



  '**************************************************************

  '* If a Delete was requested, delete the trade from the database

  '**************************************************************

  ElseIf Request.Form("Action") = "Delete" Then



              'Build the SQL string

              strSQL = "Delete * from Items Where Id = " & Request.Form("Selection") & " "



              'Create and open the database object

              Set objConn = Server.CreateObject("ADODB.Connection")

              objConn.Open "DSN=Trade"



              'Create the command object

              Set objCmd = Server.CreateObject("ADODB.Command")



              'Set the command object properties

              Set objCmd.ActiveConnection = objConn

              objCmd.CommandText = strSQL

              objCmd.CommandType = adCmdText



              'Execute the command

              objCmd.Execute



              'Display the delete string

              Response.Write "<center>The Ad has been <b>Removed</b> from the Trading Post.<br>"

              Response.Write "[ <a href='admin.asp'>Return To The Administrator</a> ]</center>"



  End If    'End If for step processing



  'Close and dereference database objects

  Set objCmd = Nothing

  objConn.Close                                        Line #342

  Set objConn = Nothing

  %>

  --- Change your mail options at http://p2p.wrox.com/manager.asp or 


Message #4 by "Randy Cornish" <rlcornish@c...> on Mon, 10 Jun 2002 00:01:21
Robert,

You submitted your posting in MIME/HTML format.  If you look below, you 
will see that much of your posting are HTML control codes and make 
reading your posting very difficult.  Since the WROX list server does not 
handle MIME/HTML very well, I respectfully suggest that you use "plain 
text" for all postings to the P2P forums.

R

> This is a multi-part message in MIME format.

------=_NextPart_000_0001_01C20E13.57F53390
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

I created a database a while back and it works great.  I am now making a
new database and I am having problems.  The .asp file that processes the
code works to add new items to the Access database and to remove items
from the database.  However, when I try to modify items in the database
I get the following error:
 
Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'objConn'
/po/TradingPost/Trade_Processor.asp, line 342
 
Does anyone have any tips to get me over this hump?
 
Thanks!
Robert
rharrigan@f...
 
************* Here is my code (Line 342 is marked below at the very end)
***************
 
<%
'Declare variables needed
Dim strInsert
Dim strValues
Dim strSQL
Dim adCmdText
Dim blnCriticalError
Dim blnFirstParameter
 
'Set required variables
adCmdText = 1
            
'*************************************************************
'* If an Add was requested, add a new trade to the database
'*************************************************************
If Request.Form("Action") = "Add" Then
 
            'Start building the SQL strings with the required fields
            strInsert = "Insert into Items (FName,LName"
            strValues = "Values('" & CStr(Request.Form("fname")) & _
                        "','" & CStr(Request.Form("lname")) & "'"
 
            
                                    *********** Add Statements Here
***********
 
            'Create and open the database object
            Set objConn = Server.CreateObject("ADODB.Connection")
            objConn.Open "DSN=Trade"
 
            'Create the command object
            Set objCmd = Server.CreateObject("ADODB.Command")
 
            'Set the command object properties
            Set objCmd.ActiveConnection = objConn
            objCmd.CommandText = strInsert & ") " & strValues & ")"
            objCmd.CommandType = adCmdText
 
            'Execute the command
            objCmd.Execute
                        
            'Display the insert string
            Response.Write "<b>Your ad will be verified and added to the
Trading Post by the next business day.</b>"
            
'*******************************************************************
'* If an Update was requested, update the trade in the database
'*******************************************************************
ElseIf Request.Form("Action") = "Update" Then
 
            'Start building the SQL string
            strSQL = "Update Items Set"
 
            'Set the first parameter flag to true
            blnFirstParameter = True
 
                                    *********** Update Statements Here
***********
 
            'Set the Where clause
            strSQL = strSQL & " Where Id = " & Request.Form("Selection")
& " "
 
            'Create and open the database object
            Set objConn = Server.CreateObject("ADODB.Connection")
            objConn.Open "DSN=Trade"
 
            'Create the command object
            Set objCmd = Server.CreateObject("ADODB.Command")
 
            'Set the command object properties
            Set objCmd.ActiveConnection = objConn
            objCmd.CommandText = strSQL
            objCmd.CommandType = adCmdText
 
            'Execute the command
            objCmd.Execute
 
            'Display the update string
            Response.Write "<center>The crewmember's information has
been <b>Updated</b> on the phone list.<br>"
            Response.Write "[ <a href='admin.asp'>Return To The
Administrator</a> ]</center>"
 
'**************************************************************
'* If a Delete was requested, delete the trade from the database
'**************************************************************
ElseIf Request.Form("Action") = "Delete" Then
 
            'Build the SQL string
            strSQL = "Delete * from Items Where Id = " &
Request.Form("Selection") & " "
            
            'Create and open the database object
            Set objConn = Server.CreateObject("ADODB.Connection")
            objConn.Open "DSN=Trade"
 
            'Create the command object
            Set objCmd = Server.CreateObject("ADODB.Command")
 
            'Set the command object properties
            Set objCmd.ActiveConnection = objConn
            objCmd.CommandText = strSQL
            objCmd.CommandType = adCmdText
 
            'Execute the command
            objCmd.Execute
 
            'Display the delete string
            Response.Write "<center>The Ad has been <b>Removed</b> from
the Trading Post.<br>"
            Response.Write "[ <a href='admin.asp'>Return To The
Administrator</a> ]</center>"
 
End If    'End If for step processing
 
'Close and dereference database objects
Set objCmd = Nothing
objConn.Close                                       <-- Line #342
Set objConn = Nothing
%>




  Return to Index