Public Cnn1 As New ADODB.Connection
Public Sub Connect()
Dim path As String
On Error GoTo ado2
Cnn1.CursorLocation = ADODB.CursorLocationEnum.adUseClient
If RS.State = 1 Then RS.Close()
'Cnn1.Open("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & path & ";Jet OLEDB:Database")
Cnn1.Open("Driver={SQL Server};Server=ServerName;Database=Databasename;Uid=Username;Pwd=;")
Exit Sub
ado2:
MsgBox("ผิดพลาดในการเปิดฐานข้อมูล กรุณาตรวจสอบ !?!" & Err.Description, vbOKOnly)
'MsgBox()
End