something like:
usage: ConnectTbls "AcmeSvr","Employees","","",true
Code:
sub ConnectTbls(ByVal pvSvr, ByVal pvDb, ByVal pvUser, ByVal pvPass, ByVal pbIsTrusted As Boolean)
vDriver = "Driver={SQL Server}"
if pbIsTrusted then
sConn = vDriver & ";Server=" & pvSvr & ";Database=" & pvDb & ";Trusted_connection=Yes;ConnectionTimeOut = 5"
else
sConn = vDriver & ";Server=" & pvSvr & ";Database=" & pvDb & "; Uid=" & pvUser & ";Pwd=" & pvPass & ";ConnectionTimeOut = 5"
end if
'cycle thru and connect all tbls needed
Dim db As Database
Dim tdf As TableDef
Set db = CurrentDb
For Each tdf In db.TableDefs
tdf.connect = sConn
Debug.Print tdf.Name; "="; tdf.Connect
Next
end sub