Dim str As String
str = "Provider=SQLOLEDB.1;Data Source=MyServer;Integrated Security=SSPI;Initial Catalog=MyBase;"
Application.CurrentProject.OpenConnection (str)
i have another question , is it possible that when i will open my ADP that it will check connect string , I wonder that it can be a modul when the ADP will be running
???
Sure, I've done similar things in a past life, setting up an INI file and reading values in. I don't have the old code samples, but I'm sure if you google - VBA Rading INI File or something, you will get the answer.
Here is how I set the data source.. htwh,
Dim DBConnResult As Boolean
DBConnResult = False
DBConnResult = ChangeADPConnection("ServerName", "DB_Name")
If DBConnResult = False Then
lcTitle = "Critical Error Connecting to Database"
lcMsg = vbCrLf & "A Critical Error Has Been Detected While Attempting to Connect to" & vbCrLf
lcMsg = lcMsg & " User ID: " & lcUser & vbCrLf
lcMsg = lcMsg & " Server: " & & vbCrLf
lcMsg = lcMsg & "Database: " & & vbCrLf & vbCrLf
lcMsg = lcMsg & "Contact Technical Support for Assistance." & vbCrLf
lnResponse = MsgBox(lcMsg, lcStyle1, lcTitle)
Application.CurrentProject.CloseConnection
Application.Quit acQuitSaveAll
End If
Function ChangeADPConnection(strServerName As String, strDBName As _
String, Optional strUN As String, Optional strPW As String) As Boolean
Dim strConnect As String
On Error GoTo EH:
Application.CurrentProject.CloseConnection
'The Provider, Data Source, and Initial Catalog arguments are required.
strConnect = "Provider=SQLOLEDB.1" & _
";Data Source=" & strServerName & _
";Initial Catalog=" & strDBName
If strUN <> "" Then
strConnect = strConnect & ";user id=" & strUN
If strPW <> "" Then
strConnect = strConnect & ";password=" & strPW
End If
Else 'Try to use integrated security if no username is supplied.
strConnect = strConnect & ";integrated security=SSPI"
End If
Application.CurrentProject.OpenConnection strConnect
ChangeADPConnection = True
Exit Function
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.