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:

Function GetProfitPercent
Dim rsRegx
Set rsRegx = Nothing
'Set rsReg = ActiveConnection
sSQL="SELECT PROFIT_PERCENT FROM t_DIRECTORY WHERE directory_id = '" & Session("UserLocationId") & "'"
    set rsRegx = server.CreateObject("adodb.recordset")
    
    rsRegx.cursorlocation = aduseclient
    rsRegx.cursortype = adkeyset
    rsRegx.open sSQL, gobjConnect
    
    if not rsRegx.eof then
        Session("PPercent") = rsRegx("PROFIT_PERCENT") & ""
    else
        Session("PPercent") = ".15"
    end if
    
    rsRegx.Close
    Set rsRegx = Nothing
    CloseDbConn
End Function

Here is the exact error I am getting:
Microsoft VBScript runtime error '800a01a8'

Object required

It errors on an Execute statement...

Thanks!

It is telling you that "Session("UserLocationId")" is not an object, it is not set. Check to make sure it is spelled correctly, and if the ID is an integer field in the database, remove the single quotes in the sSQL statement.

Or that gobjConnect does not exist, or rsRegx is not set (which above it is). But where is gobjConnect??

After messing around with it and hardcoding some numbers in and it looks like it is not getting the value out of this:

Session("PPercent") = rsRegx("PROFIT_PERCENT") & ""

If I replace reRegx("PROFIT_PERCENT") with ".12" it works just fine. I cannot figure out why it is not pulling the Profit_Percent value out of the DB. Any ideas?

Do you have a correct match, you have records? Do a count of records returned.

remove the last ' & "" ' bit from the end, there is no need for it.

Also, every column in a database is case-sensitive. Make sure that i is "PROFIT_PERCENT" and not "Profit_Percent", you know? Verify the spelling and cases.

Here is what I ended up with... I ended up creating another connection instead of calling another function that should have opened the connection (it works on a few other functions).

Function GetProfitPercent
Dim rsReg
Dim value
'OpenDbConn - did not work for me this time for whatever reason.  This is what called the function that Conn does now.

Set rsReg = Nothing
set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open gsConnect
'Set rsReg = ActiveConnection
sSQL="SELECT PROFIT_PERCENT FROM Table WHERE directory_id = '" & Session("UserLocationId") & "'"
	set rsReg = server.CreateObject("adodb.recordset")
	
	rsReg.cursorlocation = aduseclient
	rsReg.cursortype = adkeyset
	rsReg.open sSQL, Conn
    
    if not rsReg.eof then
	    Session("PPercent") = rsReg("PROFIT_PERCENT") & ""
	    value = Session("PPercent")
	else
	    Session("PPercent") = ".15"
	    value = Session("PPercent")
	end if
		
	rsReg.Close
	Set rsReg = Nothing
		
	GetProfitPercent = value
End Function

Thanks for the help.

This question has already been answered. Start a new discussion instead.