Open database

Vassago

Former Staff Turned AWF Retiree
Local time
Today, 18:10
Joined
Dec 26, 2002
Messages
4,696
I'm trying to make one database close and then open another database using this little bit of code:

Dim stAppName As String
stAppName = "MSACCESS.EXE C:\New RST Database.mdb"
Call Shell(stAppName, 1)
DoCmd.Quit acQuitSaveAll

But when it tries to open the new database, it actually tries to open a database named "New.mdb", completely cutting off "RST Database" from the name. Is there any way I can get this to work? Thanks!

Vassago:D
 
Thanks for the reply!

Unfortunately, this database isn't mine, and I can't change the name because of links to other sites. The single quote idea didn't work either. Is there any way I could set the database name to a variable and use that? Anyone have any clue on how this might work?

Thanks!

Vassago
 
add the following to a module in your database

Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

Function ShortName(ByVal LongName As String) As String
Dim sBuff As String
Dim x As Long
sBuff = Space$(512) ' make space
x = GetShortPathName(LongName, sBuff, Len(sBuff))
ShortName = Left$(sBuff, x)
End Function



Then use:

Dim stAppName As String
Dim strFileName As String
strFileName = ShortName("Your file name here")
stAppName = "MSAccess.exe " & strFileName
Call Shell(stAppName, 1)
DoCmd.Quit acQuitSaveAll

Works for ME!
 
Last edited:
Thanks everyone for your help. I talked the owner of the database into changing the name to not include the spaces and it works perfectly now. I will try your module code out as well. Thanks a lot!

Vassago
 
The benefit of getting the short file name with the API function I posted is resolving naming issues with the folder name as well. For instance, if the database is saved in a folder with a space in the name (i.e. Program Files) you will get the same conflict, as the shell command will truncate the file name at the space.
 

Users who are viewing this thread

Back
Top Bottom