Reconnecting a backend database problem with password

C

Carriolan Shinobi

Hi
I have been using this VBA code without a hitch. However it will not
work if I put a database password on the backend database. It comes up
with an invalid password error. What additional lines of coding must I
insert to make it work - thanks

Carriolan


Dim db As Database, source As String, path As String
Dim dbsource As String, i As Integer, j As Integer
Set db = dbengine.Workspaces(0).Databases(0)
'*************************************************************
'* RECOGNIZE THE PATH *
'*************************************************************
For i = Len(db.name) To 1 Step -1
If Mid(db.name, i, 1) = Chr(92) Then
path = Mid(db.name, 1, i)
'MsgBox (path)
Exit For
End If
Next
'*************************************************************
'* CHANGE THE PATH AND CONNECT AGAIN *
'*************************************************************
For i = 0 To db.tabledefs.count - 1
If db.tabledefs(i).connect <> " " Then
source = Mid(db.tabledefs(i).connect, 11)
'Debug.Print source
For j = Len(source) To 1 Step -1
If Mid(source, j, 1) = Chr(92) Then
dbsource = Mid(source, j + 1, Len(source))
source = Mid(source, 1, j)
If source <> path Then
db.tabledefs(i).connect = ";Database=" + path + dbsource
db.tabledefs(i).RefreshLink
'Debug.Print ";Database=" + path + dbsource
End If
Exit For
End If
Next
End If
Next
End Function
 
G

George Nicholson

db.tabledefs(i).connect = ";Database=" + path + dbsource & ";Pwd=myPassword"

HTH,
 
C

Carriolan Shinobi

Thanks George (been away) - Will have a go this weekend.
Best Carriolan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top