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
 
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?
 
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.
 
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

Similar Threads

command line coding 1
logging off 1
Command Line for Backup 1
Disable Command Prompt Command 6
Windows Installer message 2
shell command 2
Batch file path 4
Decompiling Access 3

Top