Searching/Saving file paths

  • Thread starter Thread starter quixote
  • Start date Start date
Q

quixote

OK..let's see if I can explain this. I am not sure how I
can query a file path.
Let's say I have a folder called Orders somewhere. Within
the Orders folder are subfolders with Order groups, eg
1000, 2000, 3000, 4000, etc.

I have a form with Order information and a button on it
that opens and Excel template. When the user clicks the
button I would like for a document to be created and
opened from the relevant directory. Her is an example of
the logic I would need.

dim strOrdGroup = 1000 (this would actually be data from a
form field)
dim strOrd = 1 (same as above)


If "X:\\SomeFolderName\Orders\1000\" & strOrdGroup & "-" &
strOrd & ".xls" exists then
Open that file

Else
create the file "X:\\SomeFolderName\Order\1000\" &
strOrdGroup & "-" & strOrd & ".xls" and open it.

End if



Thanks
 
-----Original Message-----
OK..let's see if I can explain this. I am not sure how I
can query a file path.
Let's say I have a folder called Orders somewhere. Within
the Orders folder are subfolders with Order groups, eg
1000, 2000, 3000, 4000, etc.

I have a form with Order information and a button on it
that opens and Excel template. When the user clicks the
button I would like for a document to be created and
opened from the relevant directory. Her is an example of
the logic I would need.

dim strOrdGroup = 1000 (this would actually be data from a
form field)
dim strOrd = 1 (same as above)


If "X:\\SomeFolderName\Orders\1000\" & strOrdGroup & "-" &
strOrd & ".xls" exists then
Open that file

Else
create the file "X:\\SomeFolderName\Order\1000\" &
strOrdGroup & "-" & strOrd & ".xls" and open it.

End if



Thanks
Hi Quixote,

consider using error handlers...

Declare module level object variables immediately
following the Option Explicit at the top of the module
window.

private mxlBook as object
private mxlApp as object

have a procedure that connects with the excel application
object:

private function GetExcel() as boolean
on error resume next
set mxlApp = getobject(,"Excel.application")
if err.number <>0 then
set mxlApp=new excel.application
end if
GetExcel=true
end function

call using...

if GetExcel() then

then in procedure to open workbook include:

const BASE_PATH as string = "X:\\SomeFolderName\Orders\1000
\"
dim strFile as string


strFile=base_path & strOrdGroup & "-" & strOrd & ".xls"

on error resume next
mxlApp.workbooks.open strFile

' error if book does not exist
if err.number<>0 then
mxlApp.workbooks.add

' if an error saving then want to stop
on error goto 0
mxlapp.activeworkbook.saveas strfile
end if

set mxlBook = mxlapp.activeworkbook
' do whatever with book object

please test as this is all air code...
Luck
Jonathan
 
Back
Top