Solved

change hard code path to this workbook

Posted on 2013-11-27
4
269 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 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 39681741
strDBName = ThisWorkbook.Path & "\FieldSalesData.mdb"
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 39688439
Did that help?
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 39691839
thanks
0
 
LVL 46

Expert Comment

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

Marty - MVP 2009 to 2013
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

770 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