Option Explicit
Public CN As ADODB.Connection
Private RS As ADODB.Recordset
Private Sub Form_Initialize()
'// Skapa en ny connection
Set CN = New ADODB.Connection
End Sub
Private Sub Form_Load()
Dim connectionString As String
'// Försök öppna en connection med hjälp av UDL-filen
On Error Resume Next
CN.ConnectionTimeout = 2
connectionString = getConnectionString(App.exename, Me.hwnd)
CN.Open connectionString
If Not GetState(CN.State) = "adStateOpen" Then
Kill App.path & "\" & App.exename & ".udl"
MsgBox "Felaktig 'connectionstring'. Du måste starta om programmet.", vbOKOnly + vbExclamation, "SNM - Felaktig Connectionstring"
Set CN = Nothing
Set RS = Nothing
Unload Me
End If
End Sub
Private Sub Form_Terminate()
'// Disconnecta CN och RS
CN.Close
Set CN = Nothing
Set RS = Nothing
End Sub