Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connect String ADP

Status
Not open for further replies.

tedew1

Programmer
Oct 26, 2005
31
DE
hello:)
Is it Possible that I will pass Connect String to the Access Project as parameter ??? from a file
???

bye,
sorry for my english
 
hello:)
i have done :)

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
???

bye

 
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

EH:
'MsgBox Err.Number & ": " & Err.Description, vbCritical, "Connection Error"
ChangeADPConnection = False

End Function


Steve Medvid
&quot;IT Consultant & Web Master&quot;

Chester County, PA Residents
Please Show Your Support...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top