Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

change hard code path to this workbook

Posted on 2013-11-27
4
Medium Priority
?
298 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 50

Accepted Solution

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

Expert Comment

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

Author Closing Comment

by:Fordraiders
ID: 39691839
thanks
0
 
LVL 50

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

564 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