Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 3rd, 2009, 05:19 AM
Authorized User
 
Join Date: Mar 2008
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?
 
Old September 3rd, 2009, 07:47 AM
Friend of Wrox
 
Join Date: Sep 2005
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)
 
Old September 3rd, 2009, 08:06 AM
Authorized User
 
Join Date: Mar 2008
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?
 
Old September 3rd, 2009, 10:05 PM
Friend of Wrox
 
Join Date: Sep 2005
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)
 
Old September 3rd, 2009, 11:59 PM
Authorized User
 
Join Date: Mar 2008
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! :)





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.