Solved

change hard code path to this workbook

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

791 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