Meddlesome space within folder name in code

G

GD

I thought this question was answered, but apparently not. I have a command
button on a form to open a new database, but the space between Ken & Smith in
the code below is preventing the DB from opening.

Private Sub cmdGoToPaybacks_Click()
On Error GoTo Err_cmdGoToPaybacks_Click

Dim stAppName As String

stAppName = "C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE
S:\Finance\FinCommon\Ken Smith\Paybacks\Paybacks.mdb"
Call Shell(stAppName, 1)

Exit_cmdGoToPaybacks_Click:
Exit Sub

Err_cmdGoToPaybacks_Click:
MsgBox Err.Description
Resume Exit_cmdGoToPaybacks_Click

End Sub

The warning I get is "MicroSoft Office Access can't find the database file
'S:\Finance\FinCommon\Ken.mdb'

Is there a way to account for the space in code? I don't have the option of
changing the folder name.

--
GD


Access can only have one database open at a time, though you can be linked
simultaneously to many data files. You can however program a command button
to open another instance of Access to show your other database.

You can use the command button wizard to generate code similar to below:

Private Sub btnOtherDB_Click()
On Error GoTo Err_btnOtherDB_Click

Dim stAppName As String

stAppName = "C:\Program Files\Microsoft Office\Office10\MSACCESS.EXE
FullPathName\MyApp.mdb"
Call Shell(stAppName, 1)

Exit_btnOtherDB_Click:
Exit Sub

Err_btnOtherDB_Click:
MsgBox Err.Description
Resume Exit_btnOtherDB_Click
End Sub


-Ed
 
D

Dorian

Are you sure you have the S: drive mapped?
Its best to refer to the server directly e.g.
\\server-name\folder1\folder2
since different users may have their drivesd mapped differently.
Your path should be ok provided you place it in quotes, try putting single
quotes around the path:
stAppName = "C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE
'S:\Finance\FinCommon\Ken Smith\Paybacks\Paybacks.mdb'"
or maybe doubled up double quotes:
stAppName = "C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE
""S:\Finance\FinCommon\Ken Smith\Paybacks\Paybacks.mdb"""

-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".
 
C

Clifford Bass

Hi,

Note that hard coding the path to MSACCESS.EXE is not advisable.
People can customize where to install and may have different versions than
the one you are coding. Better to use SysCmd(acSysCmdAccessDir) &
"MSACCESS.EXE ""S:\Finance\FinCommon\Ken Smith\Paybacks\Paybacks.mdb""".

Clifford Bass
 

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