Solved

Re-Link data question

Posted on 2015-01-29
10
155 Views
Last Modified: 2015-01-29
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
Comment
Question by:chestera
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
10 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 250 total points
ID: 40578716
Something close to this ...

tdf.Connect = ";DATABASE=" & DBFile & ";PWD=" & "YourPassword" & ";"
0
 

Author Comment

by:chestera
ID: 40578726
DatabaseMX

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

Alan
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 250 total points
ID: 40578734
try

dim strPassword as string

strPassword="yourPassword

change this

 tdf.Connect = ";DATABASE=" & DBFile

with

 tdf.Connect = ";DATABASE=" & DBFile& ";PWD=" & strPassword
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:chestera
ID: 40578764
Rey Obero

Tried Max code and it worked. Thank you

Alan
0
 

Author Comment

by:chestera
ID: 40578778
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
 
LVL 75
ID: 40578808
Anytime you relink .. the Password with need to be part of the Connect (aka Connection) string ... one way or another.

mx
0
 

Author Comment

by:chestera
ID: 40578809
DataBaseMX

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

Alan
0
 
LVL 75
ID: 40578813
Max ?
0
 

Author Closing Comment

by:chestera
ID: 40578832
Many thanks for your help
0
 

Author Comment

by:chestera
ID: 40578840
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question