Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 3rd, 2009, 05:19 AM
Authorized User
 
Join Date: Mar 2008
Location: , , Russia.
Posts: 74
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via ICQ to sektor
Default How to specify relative path to Access 2007 in ADO connection string? [Excel 2007]

I wanna connect to Access 2007 database from Excel 2007. When creating ADO connection string, I gotta specify FULL path to database. How to make it RELATIVE?
Reply With Quote
  #2 (permalink)  
Old September 3rd, 2009, 07:47 AM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

If you are coding this from an Excel workbook you can try as shown below:

Code:
sPAth = ThisWorkbook.Path


Set Cn = New ADODB.Connection
Cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sPAth & "MyDB.mdb;Persist Security Info=False"
Cn.ConnectionTimeout = 40
Cn.Open
Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
Reply With Quote
  #3 (permalink)  
Old September 3rd, 2009, 08:06 AM
Authorized User
 
Join Date: Mar 2008
Location: , , Russia.
Posts: 74
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via ICQ to sektor
Default

Sorry. Shasur. I didn't finish my sentence. I knew this method with ThisWorkbook.Path, but I wanted to get to know, can I omit ThisWorkbook.Path if database is located in the same folder with Excel file?
Reply With Quote
  #4 (permalink)  
Old September 3rd, 2009, 10:05 PM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi Sektor

Unfortunately the current path / Application path is not taken by the program if its left empty in the connectionstring

I feel it would take the default path that is set in the path variable - mostly Mydocuments if the path name is not mentioned for the database

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
Reply With Quote
  #5 (permalink)  
Old September 3rd, 2009, 11:59 PM
Authorized User
 
Join Date: Mar 2008
Location: , , Russia.
Posts: 74
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via ICQ to sektor
Default

By the way, yes, when I don't specify path, then home directory is taken.
If so, gonna use ThisWorkbook.Path! :)
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help! Conversion Excel 2003 VBA codes to Excel 2007 sunny76 BOOK: Excel 2007 VBA Programmer's Reference ISBN: 978-0-470-04643-2 0 August 13th, 2009 05:38 AM
Send Email from MOSS 2007 Custom Workflow Using Exchange Server 2007 GAUTAM SharePoint Admin 0 March 23rd, 2009 08:47 AM
Send Email from MOSS 2007 Workflow Using Exchange Server 2007 GAUTAM SharePoint Development 0 March 23rd, 2009 08:45 AM
Excel 2007 & Access Database Link KennethMungwira Excel VBA 0 October 22nd, 2007 08:26 AM
Relative Path Connection String fangai Classic ASP Databases 1 October 3rd, 2003 02:37 AM



All times are GMT -4. The time now is 06:31 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.