473,320 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Object required Error

rrocket
116 100+
Anyone have a clue what I am doing wrong here?

I have tried to call this function a bunch of different ways, but here is the latest:

mProfitPercent = GetProfitPercent

Here is the function that I am trying to call:
Expand|Select|Wrap|Line Numbers
  1. Function GetProfitPercent
  2. Dim rsRegx
  3. Set rsRegx = Nothing
  4. 'Set rsReg = ActiveConnection
  5. sSQL="SELECT PROFIT_PERCENT FROM t_DIRECTORY WHERE directory_id = '" & Session("UserLocationId") & "'"
  6.     set rsRegx = server.CreateObject("adodb.recordset")
  7.  
  8.     rsRegx.cursorlocation = aduseclient
  9.     rsRegx.cursortype = adkeyset
  10.     rsRegx.open sSQL, gobjConnect
  11.  
  12.     if not rsRegx.eof then
  13.         Session("PPercent") = rsRegx("PROFIT_PERCENT") & ""
  14.     else
  15.         Session("PPercent") = ".15"
  16.     end if
  17.  
  18.     rsRegx.Close
  19.     Set rsRegx = Nothing
  20.     CloseDbConn
  21. End Function
  22.  
Here is the exact error I am getting:
Microsoft VBScript runtime error '800a01a8'

Object required

It errors on an Execute statement...

Thanks!
Feb 1 '08 #1
2 4037
CroCrew
564 Expert 512MB
Hello rrocket,

I have been seeing a lot of people placing their connection strings to their databases on their ASP pages (Local String variables, directly within the open statement, and even in functions). I think newer developers and us that have a ‘few’ years under our belts start pushing the correct way again on how to connect to ones database within the ASP interface/framework.

Connection string should be stored inside of an application variable that is set within the Global.asa file of our websites. The Global.asa is a file/page that get loaded/refreshed every time the website gets started or the file itself is saved. This is “the” place to place application variables. Here is an example of a Global.asa file that has a connection to a Microsoft SQL Server, Microsoft Access Database, and Oracle Server:

Expand|Select|Wrap|Line Numbers
  1. <!-- METADATA Type="TypeLib" UUID="00000201-0000-0010-8000-00AA006D2EA4" -->
  2. <script language=VBScript runat=Server>
  3.     Sub Application_OnStart
  4.         Application("My_SQL") = "Provider=SQLOLEDB;Data Source=000.000.000.000;Initial Catalog=DatabaseName;User ID=DatabaseUser;Password=Password;"
  5.         Application("My_Access") = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Relative path to your Access database")
  6.         Application("My_Oracle") = "dsn=SystemDsnName;uid=DatabaseUser;pwd=Password;"
  7.     End Sub
  8. </script>
  9.  
Now any page can make reference to the application variables and there is only one place that the developer has to go to for updating a connection string if need be.


Hey rrocket,

You might be scratching your head trying to understand what this has to do with your question. Well, I don’t know what type of database your connection to or how your function that calls your connection string looks. Give your Global.asa file a try in place of a function to seed your connection string; it is just one less thing you will need to debug from now on.

Also, it looks like you should be using a “sub” instead of a “function”. Functions are to be used to return values.

Try one of the below snips and let us know if it worked:

If you’re using Microsoft SQL Server:
Expand|Select|Wrap|Line Numbers
  1. <%
  2. Sub GetProfitPercent()
  3.     If Not LEN(Session("UserLocationId"))>0 Then
  4.         Response.Write("Your Session has ended!")
  5.         Response.End
  6.     End IF
  7.  
  8.     Set Conn = Server.CreateObject("ADODB.Connection")
  9.         Conn.Open Application("My_SQL")
  10.         SQL = "SELECT PROFIT_PERCENT FROM t_DIRECTORY WHERE directory_id = '" & Session("UserLocationId") & "'"
  11.     Set myRS=Server.CreateObject("ADODB.Recordset")
  12.         myRS.Open SQL, Conn
  13.  
  14.     If (myRS.EOF) Then
  15.         Session("PPercent") = ".15"
  16.     Else
  17.         Session("PPercent") = myRS("PROFIT_PERCENT")
  18.     End If
  19. End Function
  20. %>
  21.  
If you’re using Microsoft Access Database:
Expand|Select|Wrap|Line Numbers
  1. <%
  2. Sub GetProfitPercent()
  3.     If Not LEN(Session("UserLocationId"))>0 Then
  4.         Response.Write("Your Session has ended!")
  5.         Response.End
  6.     End IF
  7.  
  8.     Set Conn = Server.CreateObject("ADODB.Connection")
  9.         Conn.Open Application("My_Access")
  10.         SQL = "SELECT PROFIT_PERCENT FROM t_DIRECTORY WHERE directory_id = '" & Session("UserLocationId") & "'"
  11.     Set myRS=Server.CreateObject("ADODB.Recordset")
  12.         myRS.CursorType = 1
  13.         myRS.LockType = 3
  14.         myRS.Open SQL, Conn
  15.  
  16.     If (myRS.EOF) Then
  17.         Session("PPercent") = ".15"
  18.     Else
  19.         Session("PPercent") = myRS("PROFIT_PERCENT")
  20.     End If
  21. End Function
  22. %>
  23.  
If you’re using Oracle Orical Server:
Expand|Select|Wrap|Line Numbers
  1.     If Not LEN(Session("UserLocationId"))>0 Then
  2.         Response.Write("Your Session has ended!")
  3.         Response.End
  4.     End IF
  5.  
  6.     Set Conn = Server.CreateObject("ADODB.Connection")
  7.         Conn.Open Application("My_Oracle")
  8.         SQL = "SELECT PROFIT_PERCENT FROM t_DIRECTORY WHERE directory_id = '" & Session("UserLocationId") & "'"
  9.     Set myRS=Server.CreateObject("ADODB.Recordset")
  10.         myRS.Open SQL, Conn
  11.  
  12.     If (myRS.EOF) Then
  13.         Session("PPercent") = ".15"
  14.     Else
  15.         Session("PPercent") = myRS("PROFIT_PERCENT")
  16.     End If
  17.  

Hope I was of some help~
Feb 3 '08 #2
JamieHowarth0
533 Expert 512MB
Hi rrocket,

Firstly, your error that's popping up is because of the Execute statement somewhere else in your code. When the error pops up, it should also state the address of the file generating the error, and the line number. If you can show us the appropriate code for this section of your project then we can help you debug it.

As for your function, replace these lines:
Expand|Select|Wrap|Line Numbers
  1. If Not rsRegx.EOF Then
  2. Session("PPercent") = rsRegx("PROFIT_PERCENT") & ""
  3. Else
  4. Session("PPercent") = ".15"
  5. End If
with these:
Expand|Select|Wrap|Line Numbers
  1. If Not rsRegx.EOF Then
  2. GetProfitPercent = rsRegx("PROFIT_PERCENT")
  3. Else
  4. GetProfitPercent = ".15"
  5. End If
or leave your code as is, but at line 20 before "End Function" add this:
Expand|Select|Wrap|Line Numbers
  1. GetProfitPercent = Session("PPercent")
Functions are blocks of code that receive data in, do something with it, and churn out a result as the value of the function. Subs are blocks of code that can receive and process data but do not return a value.
As you are using a function you need to specify that the value of the function is the data retrieved from your database (if any). Either block of code I have supplied will fulfil that need.

Hope it helps!

medicineworker
Feb 6 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Dave Hammond | last post by:
I've got what should be a simple assignment of either an element value or a default string to a variable, but when the element doesn't exist I get an "Object required" error rather than an...
0
by: muralidharan | last post by:
WebForm1.aspx Code: <%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %> <ComponentArt:TreeView id="TreeView1" Height="520"...
9
by: Remulac | last post by:
Hello, I'm trying to get the value out of a dropdown list box and assign it to a variable. When I click on the list box, I invoke this line of code. I get the error, "Object reference not set...
3
by: Adriano | last post by:
Hello, when I try to print something, either DataGrid or from Crystal Report viever the folowing error message appears and cancels printing: Object reference not set to an instance of an...
0
by: Deepak C.G via .NET 247 | last post by:
I want to dispose the image object in my child form, unless I won't dispose this object i can't delete the image file in my folder. I get this error in MDIparent form "An unhandled exception...
8
by: ST | last post by:
Hello everyone, Can anyone help me with this error above when I debug my web app project in vstudio.net?? I can't figure it out! It was working fine for months, and now all of a sudden it's not!!...
1
by: Don | last post by:
I'm getting the following exception displayed in the task list at design time for my project: "Code generation for property 'Controls' failed. Error was: 'Object reference not set to an...
4
by: ink | last post by:
Hi All I am relatively new to doing this and i think that i am making some king of school boy error. The error i am getting is on the following line of code. XmlSerializer xs = new...
4
by: livmacca | last post by:
Hi, I am new to VB .Net programming and is trying to create a webpage. I encountered the following error and is totally clueless on how to make it work: ...
14
by: chromis | last post by:
Hi, I've been trying to implement a more OOP oriented approach to dealing with user security on one of my websites, and I am trying to validate the user against an array of roles, however I am...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.