• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

Re-Link data question

Hi EE

I have the following code to re-link my data
Dim path
path = "C:\PPTdata"
DBFile = CurrentProject.path & "\PPTdata.mdb"
strFile = Dir(DBFile)
If strFile <> "" Then
    With CurrentDb
        For Each tdf In .TableDefs
            If tdf.Connect Like "*PPTdata.mdb*" Then
                tdf.Connect = ";DATABASE=" & DBFile
                tdf.RefreshLink
            End If
        Next
    End With
    MsgBox "Link PPTdata.mdb"
Else
    MsgBox "Problem"
End If

The data is password protected how would I modify the code to include password

chestera
0
chestera
Asked:
chestera
  • 6
  • 3
2 Solutions
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Something close to this ...

tdf.Connect = ";DATABASE=" & DBFile & ";PWD=" & "YourPassword" & ";"
0
 
chesteraAuthor Commented:
DatabaseMX

Yep I tried  password=pwd  after the DBfile couldn't get the correct syntax. I will try now
Thank you

Alan
0
 
Rey Obrero (Capricorn1)Commented:
try

dim strPassword as string

strPassword="yourPassword

change this

 tdf.Connect = ";DATABASE=" & DBFile

with

 tdf.Connect = ";DATABASE=" & DBFile& ";PWD=" & strPassword
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
chesteraAuthor Commented:
Rey Obero

Tried Max code and it worked. Thank you

Alan
0
 
chesteraAuthor Commented:
DatabaseMX

Your line of code Worked fine.

 I know this is not part of the question but I am running the program from a development folder which also contains the data.
DBfile = currentProjectpath.Path picks up the Development folder and links to the data.mdb
The data is going to reside on a server so would like to re-link to the server. Do I   need different code to achieve this or can it be modified.

Alan
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Anytime you relink .. the Password with need to be part of the Connect (aka Connection) string ... one way or another.

mx
0
 
chesteraAuthor Commented:
DataBaseMX

Sorry Max forget last responce from me
I just change the DBfile = ServeData

Alan
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Max ?
0
 
chesteraAuthor Commented:
Many thanks for your help
0
 
chesteraAuthor Commented:
DatabaseMX
Sorry for the confusion MX I asked another  question see below
 I know this is not part of the question but I am running the program from a development folder which also contains the data.
DBfile = currentProjectpath.Path picks up the Development folder and links to the data.mdb
The data is going to reside on a server so would like to re-link to the server. Do I   need different code to achieve this or can it be modified.

I worked it out
Instead of DBfile = currentProject.Path
I used
DBfile = ServicePath\Data.mdb
All works fine

Alan
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now