In VBA, is it good practice to set an object to Nothing before declaring a new instance of it?
For example:
Private Sub SetupConn()
Const Provider As String = "sqloledb"
Const LanDataSource As String = "127.0.0.1"
Const WanDataSource As String = "mail.12345678.biz:12345"
Dim UserName As String
Dim Password As String
UserName = "myusername"
Password = "mypassword"
Here is where I wonder if I should close the connection or set it to nothing before reopening to a new one.
Set mDBconn = New ADODB.Connection
Select Case mConnMethod
Case WAN
mConnStr = "Provider='" & Provider & ";Data Source=" & WanDataSource _
& ";User ID=" & UserName & ";Password=" & Password
Case Lan
mConnStr = "Provider='" & Provider & ";Data Source=" & LanDataSource _
& ";User ID=" & UserName & ";Password=" & Password
End Select
End Sub
The scenario is that a user is on the road, using a mobile data connection, he arrives at the office and wants to go straight to a high speed wifi connection without closing and reopening the program. In this case what I would do is set the connection method to LAN and call this sub with a reset parameter.