Dreamweaver
Well-known member
- Local time
- Today, 14:15
- Joined
- Nov 28, 2005
- Messages
- 2,467
I use this to link all my tables since 2005 but now find I will need to add a password to the datafile.
I know I've seen this but have got no search results that help and I do feel a bit silly having to ask
I need to add a password into the connection string code i use below hopefully someboody will be able to put me out of my misery thanks
I know I've seen this but have got no search results that help and I do feel a bit silly having to ask

I need to add a password into the connection string code i use below hopefully someboody will be able to put me out of my misery thanks
Code:
Function AttachTable(StrTable As String, StrPath As String) As String
Dim dbs As Database
Dim tdf As TableDef
Dim fld As Field
Dim strPrefix As String
Dim strNewConnect As String
On Error GoTo ErrorHandler
Set dbs = CurrentDb()
[COLOR=Blue]strPrefix = ";DATABASE="
strNewConnect = strPrefix & StrPath[/COLOR]
Set tdf = dbs.TableDefs(StrTable)
ExistingTable:
[COLOR=blue]tdf.Connect = strNewConnect[/COLOR]
tdf.RefreshLink
AttachTable = ""
GoTo Done
ErrorHandler:
Select Case Err.Number
Case 3011
AttachTable = "Could not find the table " & StrTable & " in " & StrPath
Case Else
AttachTable = Err.Description
End Select
Done:
dbs.Close
End Function
Function LinkAtStartup(StrPath As String)
Dim m_Db As Database 'This Database
Dim M_Links As DAO.Recordset 'Holds The Programs Linked Tables Names
Dim BooErr As Boolean 'Used To Show If Any Error Reported
Dim BooSample As Boolean 'Tag To Show If Sample Data Linked To
Dim intCount As Integer 'Total Linked Tables
Dim IntCounter As Integer 'Tables Attached
Dim E As Variant 'Hold Any Error Info From Link Table
On Error GoTo HandleErr
Set m_Db = CurrentDb()
Set M_Links = m_Db.OpenRecordset("StblLinkedTables", dbOpenTable)
M_Links.MoveLast
intCount = M_Links.RecordCount
'Make Shure The Data File Exists First
If adhFileExists(StrPath) Then
M_Links.MoveFirst 'Make Shure Of First Record
DoCmd.OpenForm Strfrm
Forms(Strfrm)!txtLink = StrPath
Forms(Strfrm)!txtTotal = intCount
Forms(Strfrm).Repaint
'MsgBox StrPath & vbCrLf & "Tables: " & M_Links.RecordCount
Do While Not M_Links.EOF
E = AttachTable(M_Links("txtTable"), StrPath)
If Not E = "" Then
If MsgBox(E, vbExclamation + vbYesNo, "Continue ?") = vbNo Then
GoTo HandleExit
End If
End If
IntCounter = IntCounter + 1
Forms(Strfrm)!txtCount = IntCounter
Forms(Strfrm).Repaint
M_Links.MoveNext
Loop
Else
MsgBox "Cannot Find " & StrPath & vbCrLf & "Please Open Preferences And Select Your Data Files Location", vbCritical, "File Not Found"
Exit Function
End If
HandleExit:
DoCmd.Close acForm, Strfrm
DoCmd.Close acForm, "SfrmLinkAtStartup"
M_Links.Close
Exit Function
HandleErr:
If Err.Number = 91 Then
Exit Function
End If
MsgBox Err.Number & Err.Description
Resume HandleExit
End Function