PDA

View Full Version : Calling subs when in a sub.


Mhtml
10-27-2002, 07:16 AM
How can I call a sub when in a sub? I keep getting an error saying that my recordset is undefined, but it is defined in the sub CreateConns() and I call it in another sub like this:

sub GetNews()
CreateConns()
....

But it doesn't seem to work.

whammy
10-27-2002, 08:45 AM
Ahh... I ran into that problem as well awhile back.

The problem is you need to Dimension your connection string variables at the top of the page - I usually use Option Explicit to help avoid these kinds of problems.

:)

Mhtml
10-27-2002, 09:05 AM
I usually use option explicit but I didn't for some reason in this script.

Now I am getting a syntax error where I set the variables..

dim recordset, connection, sConnString, Sql_select
sub CreateConns()
sql_select="SELECT * FROM News where Month ="&request.Form("Month")
sConnString="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("db\odysseymain.mdb") & ";"
Set connection = Server.CreateObject("ADODB.connection")
connection.Open sConnString &_
Set recordset = Server.CreateObject("ADODB.Recordset")
end sub
sub KillConns()
Set recordset = Nothing
connection.Close
Set connection = Nothing
End Sub


I'm not sure why though...weird.

whammy
10-27-2002, 09:12 AM
connection.Open sConnString &_

Mhtml
10-27-2002, 09:22 AM
I had to rename my connection variables as well, and now I'm getting an error saying that object doesn't support this property or method :

rs.Open sql_select,conn

Mhtml
10-27-2002, 09:24 AM
I figured it, I just had rs=server.createobject("adodb.recordset") without set in front of it...

Thanks whammy!:D