Solved

change hard code path to this workbook

Posted on 2013-11-27
4
248 Views
Last Modified: 2013-12-03
excel vba...2010

What I need:
I need to change this hard code path so this  access database will be read from any path where this workbook is opened from.
?





Dim cn As ADODB.Connection, rs As ADODB.Recordset
Dim strConnection As String, strDBName As String, strPassword As String
Dim strTime As String
   On Error GoTo DataIsCurrent_Error


strDBName = "C:\Program Files\FieldSales\FieldSalesData.mdb"


strPassword = "123QQxx0919AZAZazaz"
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBName _
            & ";Mode=ReadWrite;Persist Security Info=False" _
            & ";Jet OLEDB:Database Password=" & strPassword
Set cn = New ADODB.Connection
cn.Open strConnection
Set rs = New ADODB.Recordset
0
Comment
Question by:fordraiders
  • 3
4 Comments
 
LVL 45

Accepted Solution

by:
Martin Liss earned 500 total points
Comment Utility
strDBName = ThisWorkbook.Path & "\FieldSalesData.mdb"
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
Did that help?
0
 
LVL 3

Author Closing Comment

by:fordraiders
Comment Utility
thanks
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

772 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

10 Experts available now in Live!

Get 1:1 Help Now