Guys I'm a newbie with OOP (Object-oriented programming)
I need your assistance to develop a connection inside a class so I can get/access this connection on a module.
Here below the function the connects to the SQL Server that is working fine.
What I need is make reference to this function outside the class so I can use SQL strings to retrieve the data from the server.
class Name:clsDbCon
I need your assistance to develop a connection inside a class so I can get/access this connection on a module.
Here below the function the connects to the SQL Server that is working fine.
What I need is make reference to this function outside the class so I can use SQL strings to retrieve the data from the server.
class Name:clsDbCon
Code:
[COLOR=#0000cd]Public Function [/COLOR]conectToSQLServer(strServerName, strDatabaseName [COLOR=#0000cd]As String[/COLOR])
[COLOR=#0000cd]Dim[/COLOR] conn [COLOR=#0000cd]As[/COLOR] ADODB.Connection
[COLOR=#0000cd]Set[/COLOR] conn = [COLOR=#0000cd]New [/COLOR]ADODB.Connection
[COLOR=#0000cd]With [/COLOR]conn
[COLOR=#006400] ' DSN-less connection using the ODBC driver[/COLOR]
.Open "Driver={SQL Server};" & _
"Server=" & strServerName & ";UID=USER;" & _
"PWD=PASSWORD;" & _
"Database=" & strDatabase
.Close
[COLOR=#0000cd] End With[/COLOR]
[COLOR=#0000cd]Set[/COLOR] conn = [COLOR=#0000cd]Nothing
End Function[/COLOR]
Last edited: