Using Process.Start()!

BigSi

Member
Joined
Feb 6, 2003
Messages
22
Hi,

Im using the Process.Start method to open Access which is working ok until I use the arguments.

Currently to open a specific access database, i use:
Code:
System.Diagnostics.Process.Start("MSAccess.exe", "C:\mydatabase\databasename")
This works fine, but when i have a directory with a space in it such as

my database

I get an error as access looks for the .mdb file called my!

Is there a way to prevent the space causing this error by suplementing the space character with some thing else?

cheers,
Si
 
Code:
Dim MyDatabase as string = "MyDB.mdb"

System.Diagnostics.Process.Start("MSAccess.exe", "C:\mydatabase\" & MyDatabase)

Andy
 
Sorry Andy,
I think I havnt clearly said what the problem is!

the following code works fine as there is no space in the directory name:
Code:
System.Diagnostics.Process.Start("MSAccess.exe", "C:\mydatabase\databasename")
but this code doesnt as there is a space in the directory name
Code:
System.Diagnostics.Process.Start("MSAccess.exe", "C:\my database\databasename")

I am trying to find out if there is something I should subsititute for the space character such as my%database/databasename
 
what you can do is the 8 char naming system

e.g.

Code:
System.Diagnostics.Process.Start("MSAccess.exe", "c:\mydata~1\databasename")

This will work. What was done was the parameter was truncated because a space existed. truncate to 8 chars.

Or

The best method is to double quote

Code:
System.Diagnostics.Process.Start("MSAccess.exe", """c:\my database\databasename""")

Both will work

Also just to note: you has a apostrophe in there with invaildates the path


Andy
 
Andy,

Thanks for your help andy - the double quote worked perfectly! - the only problem now is that I should have mentioned I was working with variables so the location of the mdb file could be anything!

Do you know if there is a way to adapt the double quote to use it alongside a string variable?

Otherwise I guesse Im gonna have to break down all the directories and discover which ones have spaces, so I can convert them to the 8 char naming system.


Once again - thanks for your help!

(oh - and that apostraphe should not have been there, I accidently put it on whilst posting this message. well spotted though!)
 
yup

Code:
Dim MyPath As String = Application.Startupparth & "\"
Dim MyDatabaseName As String = "MyName.mdb"

System.Diagnostics.Process.Start("MSAccess.exe", """" & MyPath & MyDatabaseName & """")

That will work fine

Andy
 
Hurray!!

- just found a way to use a string variable!
[VB]
Dim DatbaseLocation as string
DatabaseLocation = "C:\my database\databasename"
DatabaseLocation = """" & databaseLocation & """"

System.Diagnostics.Process.Start("MSAccess.exe", DatabaseLocation)
[/code]

Thanks again Andy for your help!
 
Back
Top