Solved

Re-Link data question

Posted on 2015-01-29
10
147 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
  • 6
  • 3
10 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) 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 119

Assisted Solution

by:Rey Obrero
Rey Obrero 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
 

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
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)

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

895 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now