Solved

Re-Link data question

Posted on 2015-01-29
10
146 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

746 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

13 Experts available now in Live!

Get 1:1 Help Now