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
"IT Consultant & Web Master"
Chester County, PA Residents
Please Show Your Support...