PC Review


Reply
Thread Tools Rate Thread

Absolute verses Relative file path in SQL

 
 
=?Utf-8?B?Uml2ZXJHdWxseQ==?=
Guest
Posts: n/a
 
      19th Oct 2007
Hi,

I have several spreadsheets in the same folder that are consolidated into
one spreadsheet using the MS Query feature in Excel. I have reproduced a
part of the query below. The 'FROM' line states an absolute reference:
J:\Budget\filename.xls; is there a way to tell SQL that the file it is
looking for is in the base (current) folder so I can simply state the file
name without the path.

SELECT tblOwnTax.CODE, LEFT(Description,18), MID(DESCRIPTION,30,30),
tblOwnTax.PYR3, tblOwnTax.PYR2, tblOwnTax.PYR1, tblOwnTax.CYR,
tblOwnTax.CYR1, tblOwnTax.CYR2, tblOwnTax.CYR3, tblOwnTax.CYR4,
tblOwnTax.CYR5 FROM `J:\Budget\GOR_Revenue`.tblOwnTax tblOwnTax
WHERE (tblOwnTax.CODE Like '%-GO%')

Union SELECT tblPIPS.CODE, LEFT(Description,18),
MID(DESCRIPTION,30,30), tblPIPS.PYR3, tblPIPS.PYR2, tblPIPS.PYR1,
tblPIPS.CYR, tblPIPS.CYR1, tblPIPS.CYR2, tblPIPS.CYR3, tblPIPS.CYR4,
tblPIPS.CYR5 FROM `J:\Budget\GOR_Revenue`.tblPIPS tblPIPS WHERE
(tblPIPS.CODE Like '%-GO%')

Many thanks in advance.

 
Reply With Quote
 
 
 
 
SteveM
Guest
Posts: n/a
 
      21st Oct 2007
Use the Object Path and Name properties. E.g.,

Dim str as String
str = ActiveWorkbook.Path
str = str & AcvtiveWorkbook.Name

That will give you both the path and file name of the workbook. Then
replace any absolute references with the String (str) value using the
"&" to properly concatenate.

SteveM



On Oct 19, 6:10 pm, RiverGully <RiverGu...@discussions.microsoft.com>
wrote:
> Hi,
>
> I have several spreadsheets in the same folder that are consolidated into
> one spreadsheet using the MS Query feature in Excel. I have reproduced a
> part of the query below. The 'FROM' line states an absolute reference:
> J:\Budget\filename.xls; is there a way to tell SQL that the file it is
> looking for is in the base (current) folder so I can simply state the file



> name without the path.
>
> SELECT tblOwnTax.CODE, LEFT(Description,18), MID(DESCRIPTION,30,30),
> tblOwnTax.PYR3, tblOwnTax.PYR2, tblOwnTax.PYR1, tblOwnTax.CYR,
> tblOwnTax.CYR1, tblOwnTax.CYR2, tblOwnTax.CYR3, tblOwnTax.CYR4,
> tblOwnTax.CYR5 FROM `J:\Budget\GOR_Revenue`.tblOwnTax tblOwnTax
> WHERE (tblOwnTax.CODE Like '%-GO%')
>
> Union SELECT tblPIPS.CODE, LEFT(Description,18),
> MID(DESCRIPTION,30,30), tblPIPS.PYR3, tblPIPS.PYR2, tblPIPS.PYR1,
> tblPIPS.CYR, tblPIPS.CYR1, tblPIPS.CYR2, tblPIPS.CYR3, tblPIPS.CYR4,
> tblPIPS.CYR5 FROM `J:\Budget\GOR_Revenue`.tblPIPS tblPIPS WHERE
> (tblPIPS.CODE Like '%-GO%')
>
> Many thanks in advance.



 
Reply With Quote
 
SteveM
Guest
Posts: n/a
 
      21st Oct 2007
Correction:

Sub ShowPath()
Dim str As String
str = ActiveWorkbook.Path
str = str & "\" & ActiveWorkbook.Name
MsgBox str

End Sub


On Oct 20, 10:19 pm, SteveM <sbm...@vzavenue.net> wrote:
> Use the Object Path and Name properties. E.g.,
>
> Dim str as String
> str = ActiveWorkbook.Path
> str = str & AcvtiveWorkbook.Name
>
> That will give you both the path and file name of the workbook. Then
> replace any absolute references with the String (str) value using the
> "&" to properly concatenate.
>
> SteveM
>
> On Oct 19, 6:10 pm, RiverGully <RiverGu...@discussions.microsoft.com>
> wrote:
>
> > Hi,

>
> > I have several spreadsheets in the same folder that are consolidated into
> > one spreadsheet using the MS Query feature in Excel. I have reproduced a
> > part of the query below. The 'FROM' line states an absolute reference:
> > J:\Budget\filename.xls; is there a way to tell SQL that the file it is
> > looking for is in the base (current) folder so I can simply state the file
> > name without the path.

>
> > SELECT tblOwnTax.CODE, LEFT(Description,18), MID(DESCRIPTION,30,30),
> > tblOwnTax.PYR3, tblOwnTax.PYR2, tblOwnTax.PYR1, tblOwnTax.CYR,
> > tblOwnTax.CYR1, tblOwnTax.CYR2, tblOwnTax.CYR3, tblOwnTax.CYR4,
> > tblOwnTax.CYR5 FROM `J:\Budget\GOR_Revenue`.tblOwnTax tblOwnTax
> > WHERE (tblOwnTax.CODE Like '%-GO%')

>
> > Union SELECT tblPIPS.CODE, LEFT(Description,18),
> > MID(DESCRIPTION,30,30), tblPIPS.PYR3, tblPIPS.PYR2, tblPIPS.PYR1,
> > tblPIPS.CYR, tblPIPS.CYR1, tblPIPS.CYR2, tblPIPS.CYR3, tblPIPS.CYR4,
> > tblPIPS.CYR5 FROM `J:\Budget\GOR_Revenue`.tblPIPS tblPIPS WHERE
> > (tblPIPS.CODE Like '%-GO%')

>
> > Many thanks in advance.





 
Reply With Quote
 
=?Utf-8?B?Uml2ZXJHdWxseQ==?=
Guest
Posts: n/a
 
      21st Oct 2007
Thank you .. this is of use to me.

But, how can I blend this VBA code in with my SQL code. If a variable
(str) is defined in VBA, can I use (str) in my SQL code and continue to use
an absolute reference? I'm working of menu Data - Import External Data -
MS Query (in Excel 2003)

What I was thinking was to switch my SQL code to use a relative reference
(eg .\filename.xls), but first using VBA to establish the current directory
to that of the active workbook.

When I do this, I get an error message the first time the SQL runs after
moving the workbooks to a new folder. When I open and close the SQL code it
then works fine. I wouldn't want the users of my spreadsheet to have to do
this everytime they move the spreadsheets to a new folder.

Please assist some more.... many thanks.



"SteveM" wrote:

> Correction:
>
> Sub ShowPath()
> Dim str As String
> str = ActiveWorkbook.Path
> str = str & "\" & ActiveWorkbook.Name
> MsgBox str
>
> End Sub
>
>
> On Oct 20, 10:19 pm, SteveM <sbm...@vzavenue.net> wrote:
> > Use the Object Path and Name properties. E.g.,
> >
> > Dim str as String
> > str = ActiveWorkbook.Path
> > str = str & AcvtiveWorkbook.Name
> >
> > That will give you both the path and file name of the workbook. Then
> > replace any absolute references with the String (str) value using the
> > "&" to properly concatenate.
> >
> > SteveM
> >
> > On Oct 19, 6:10 pm, RiverGully <RiverGu...@discussions.microsoft.com>
> > wrote:
> >
> > > Hi,

> >
> > > I have several spreadsheets in the same folder that are consolidated into
> > > one spreadsheet using the MS Query feature in Excel. I have reproduced a
> > > part of the query below. The 'FROM' line states an absolute reference:
> > > J:\Budget\filename.xls; is there a way to tell SQL that the file it is
> > > looking for is in the base (current) folder so I can simply state the file
> > > name without the path.

> >
> > > SELECT tblOwnTax.CODE, LEFT(Description,18), MID(DESCRIPTION,30,30),
> > > tblOwnTax.PYR3, tblOwnTax.PYR2, tblOwnTax.PYR1, tblOwnTax.CYR,
> > > tblOwnTax.CYR1, tblOwnTax.CYR2, tblOwnTax.CYR3, tblOwnTax.CYR4,
> > > tblOwnTax.CYR5 FROM `J:\Budget\GOR_Revenue`.tblOwnTax tblOwnTax
> > > WHERE (tblOwnTax.CODE Like '%-GO%')

> >
> > > Union SELECT tblPIPS.CODE, LEFT(Description,18),
> > > MID(DESCRIPTION,30,30), tblPIPS.PYR3, tblPIPS.PYR2, tblPIPS.PYR1,
> > > tblPIPS.CYR, tblPIPS.CYR1, tblPIPS.CYR2, tblPIPS.CYR3, tblPIPS.CYR4,
> > > tblPIPS.CYR5 FROM `J:\Budget\GOR_Revenue`.tblPIPS tblPIPS WHERE
> > > (tblPIPS.CODE Like '%-GO%')

> >
> > > Many thanks in advance.

>
>
>
>
>

 
Reply With Quote
 
=?Utf-8?B?Uml2ZXJHdWxseQ==?=
Guest
Posts: n/a
 
      21st Oct 2007
Sub SetDirectoryPath()
' Get current directory to equal that of the active workbook
ChDir ActiveWorkbook.Path
Calculate
ActiveWorkbook.Save

End Sub

Then my SQL code can use the relative reference syntax '.\filename.xls'

Problem is after moving spreadsheet to a new folder, the first time the SQL
code is called upon it gives an error and only works after first opening and
closing the SQL code.



"SteveM" wrote:

> Correction:
>
> Sub ShowPath()
> Dim str As String
> str = ActiveWorkbook.Path
> str = str & "\" & ActiveWorkbook.Name
> MsgBox str
>
> End Sub
>
>
> On Oct 20, 10:19 pm, SteveM <sbm...@vzavenue.net> wrote:
> > Use the Object Path and Name properties. E.g.,
> >
> > Dim str as String
> > str = ActiveWorkbook.Path
> > str = str & AcvtiveWorkbook.Name
> >
> > That will give you both the path and file name of the workbook. Then
> > replace any absolute references with the String (str) value using the
> > "&" to properly concatenate.
> >
> > SteveM
> >
> > On Oct 19, 6:10 pm, RiverGully <RiverGu...@discussions.microsoft.com>
> > wrote:
> >
> > > Hi,

> >
> > > I have several spreadsheets in the same folder that are consolidated into
> > > one spreadsheet using the MS Query feature in Excel. I have reproduced a
> > > part of the query below. The 'FROM' line states an absolute reference:
> > > J:\Budget\filename.xls; is there a way to tell SQL that the file it is
> > > looking for is in the base (current) folder so I can simply state the file
> > > name without the path.

> >
> > > SELECT tblOwnTax.CODE, LEFT(Description,18), MID(DESCRIPTION,30,30),
> > > tblOwnTax.PYR3, tblOwnTax.PYR2, tblOwnTax.PYR1, tblOwnTax.CYR,
> > > tblOwnTax.CYR1, tblOwnTax.CYR2, tblOwnTax.CYR3, tblOwnTax.CYR4,
> > > tblOwnTax.CYR5 FROM `J:\Budget\GOR_Revenue`.tblOwnTax tblOwnTax
> > > WHERE (tblOwnTax.CODE Like '%-GO%')

> >
> > > Union SELECT tblPIPS.CODE, LEFT(Description,18),
> > > MID(DESCRIPTION,30,30), tblPIPS.PYR3, tblPIPS.PYR2, tblPIPS.PYR1,
> > > tblPIPS.CYR, tblPIPS.CYR1, tblPIPS.CYR2, tblPIPS.CYR3, tblPIPS.CYR4,
> > > tblPIPS.CYR5 FROM `J:\Budget\GOR_Revenue`.tblPIPS tblPIPS WHERE
> > > (tblPIPS.CODE Like '%-GO%')

> >
> > > Many thanks in advance.

>
>
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Script w/relative path that sends absolute path to a folder to theclipboard? StargateFanNotAtHome@mailinator.com Microsoft Outlook VBA Programming 3 24th Mar 2009 01:32 PM
Changing the default file path from absolute to relative =?Utf-8?B?VER1bms=?= Microsoft Frontpage 4 16th Dec 2005 02:15 AM
Relative path vs. absolute path possible in storing pictures? StargateFanFromWork Microsoft Access Getting Started 5 2nd Dec 2005 09:29 AM
Anyway to replace absolute file path in formula with relative or use Info(directory)? RocketDude Microsoft Excel Discussion 1 18th Aug 2005 06:00 PM
There are any Path or Directory function to convert an absolute pathto a relative path? Ffelagund Microsoft VC .NET 2 8th Mar 2004 07:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:25 PM.