Command Line w/Unknown paths?

J

John G

Running MS Access 2003 on Windows XP
Is it possible to run a command line switch without knowing the exact paths?
The following command line works good as long as the files "Prg.mde" and
"secure.mdw" are in C:\Program Files\myFolder\.

Shell pathname:=("""C:\Program Files\Microsoft
Office\OFFICE11\MSACCESS.EXE"" ""C:\Program Files\myFolder\Prg.mde"" /WRKGRP
""C:\Program Files\myFolder\secure.mdw""")

I know that the files will be at "C:\Documents and
Settings\username\Application Data" (in Windows XP) but the username is
different on every computer. So if the exact path of files "PRG.mde" and
"secure.mdw" is not known; is there a way to use the following in the above
command line?

SpecFolder(CSIDL_APPDATA) 'Returns "C:\Documents and
Settings\username\Application Data" (in Windows XP) and returns
"C:\Users\username\AppData\Roaming" (in Windows Vista)
dbPath = SpecFolder(CSIDL_APPDATA) & "\myFolder\Prg.mde" 'Returns
"C:\Documents and Settings\username\Application Data\myFolder\Prg.mde"

Thanks in advance.

John G
 
C

Chris O'C via AccessMonster.com

Use environment variables. The built in environment variable you want is %
AppData%. For Windows XP it returns

{SystemDrive}:\Documents and Settings\{username}\Application Data

For Vista and Windows 7 it returns

{SystemDrive}:\Users\{username}\AppData\Roaming

Example usage:

%AppData%\myFolder\Prg.mde

Chris
 
P

Pendragon

Do a search in this newsgroup for "Get computer names" or something to that
effect. Once you modify the code accordingly, you could set a string
variable to the username and create the full path and file name from there.

dim strCompName as string
dim strFilePathname as string

strCompName = {use the function you'll find in your search or use this
variable in that function to get the computer name}

strPathFileName = "C:\Program Files\" & strCompName & "\Prg.mde"

or however the full path and file name needs to read.

HTH!
 
J

John G

Chris,
Thanks for your reply.

However, ""%AppData%\myFolder\Prg.mde"" doesn't work. Error message says
"The command line you used to start Microsoft Office Access contains an
option that Microsoft Office Access doesn't recognize." "Exit and restart
Microsoft Office Access using valid command-line options."
I tried %AppData% & ""\myFolder\Prg.mde""
and ""%AppData% & \myFolder\Prg.mde""
and I have also tried ""%AppData%\myFolder\Prg.mde"".
How should I be using it? Maybe not enough quotes?
 
C

Chris O'C via AccessMonster.com

The problem is because there are spaces in the path. It's why we'd like to
shoot developers who think it's a good idea to use any characters outside of
the alphabet, numbers and the underscore to name things. They waste our time.


This command line worked for me (1 line, not 2, as it may appear below):

"%AppData%\myFolder\Prg.mde" "C:\Program Files\Microsoft Office\OFFICE11\
MSACCESS.EXE"

Chris
 
D

Douglas J. Steele

While %AppData% works in BAT files, in VBA, you need to use the Environ
function:

Shell pathname:=("""C:\Program Files\Microsoft
Office\OFFICE11\MSACCESS.EXE"" """ & Environ("AppData") & "\Prg.mde""
/WRKGRP
""" & Environ("AppData") & "\secure.mdw""")

Another alternative would be to use the code from
http://www.mvps.org/access/api/api0054.htm to determine the location.
 
C

Chris O'C via AccessMonster.com

Thanks Doug.

Chris

While %AppData% works in BAT files, in VBA, you need to use the Environ
function:

Shell pathname:=("""C:\Program Files\Microsoft
Office\OFFICE11\MSACCESS.EXE"" """ & Environ("AppData") & "\Prg.mde""
/WRKGRP
""" & Environ("AppData") & "\secure.mdw""")

Another alternative would be to use the code from
http://www.mvps.org/access/api/api0054.htm to determine the location.
 
J

John G

Thanks Doug!

I was trying to use SpecFolder(CSIDL_APPDATA) which I got from
http://www.mvps.org/access/api/api0054.htm but I didn't know how to use it in
the command line. See my first post.

John G

Douglas J. Steele said:
While %AppData% works in BAT files, in VBA, you need to use the Environ
function:

Shell pathname:=("""C:\Program Files\Microsoft
Office\OFFICE11\MSACCESS.EXE"" """ & Environ("AppData") & "\Prg.mde""
/WRKGRP
""" & Environ("AppData") & "\secure.mdw""")

Another alternative would be to use the code from
http://www.mvps.org/access/api/api0054.htm to determine the location.
 
D

Douglas J. Steele

Copy everything in the shaded area (between Code Start and Code End) into a
new module (not a class module nor a module associated with a form or
report).

Change

Shell pathname:=("""C:\Program Files\Microsoft
Office\OFFICE11\MSACCESS.EXE"" ""C:\Program Files\myFolder\Prg.mde"" /WRKGRP
""C:\Program Files\myFolder\secure.mdw""")

to

Dim strPath As String

strPath = SpecFolder(CSIDL_APPDATA)
Shell _
pathname:=("""C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE""
""" & _
strPath & "\Prg.mde"" /WRKGRP """ & strPath & "\secure.mdw""")


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



John G said:
Thanks Doug!

I was trying to use SpecFolder(CSIDL_APPDATA) which I got from
http://www.mvps.org/access/api/api0054.htm but I didn't know how to use it
in
the command line. See my first post.

John G
 
J

John G

That is what I was looking for. I didn't have the quotes in the proper place
when I tried it before, but now I do thanks to you!

John G
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top