Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A Function that returns an ADO Connection

Status
Not open for further replies.

Guru2B

Programmer
May 24, 2000
77
GB
Hey all!

I thought I read somewhere that it is best to use a function that returns a connection object whenever a connection object is used thereby keeping the connections centralized.

I cannot recall what I have to do to accomplish this, I have tried something simple, but find that I cannot reuse the connection.

The function looks a little like this:

Public function GetNewConnection()as connection
if conn is nothing then
set conn=new connection
conn.open (blah blah blah)
end if

set GetNewConnection=conn
end function

When I use it:

Private sub Save()
set thisConn=new Connection
set thisConn=GetNewConnection

rs.open (whatever)
end sub

This method is called from another form. The first time it is called, no problems. The second time though, the connection object's state is 0. Closed.

Can someone please tell me what I am doing wrong?

Thanks in advance
Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top