• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

running a Access 97 .mdb database through Visual Basic...still giving me -2147024894 cannot find file specified but exists!

I've got the following coding:

Dim Wsh As New WSHShell
    'Set Wsh = CreateObject("WScript.Shell")
    Dim LocalDb As String
        ''set the localdb to the exact path and filename to the database you want opening
    LocalDb = "C:\Fkpuds\Template\schedulemaker.mdb"
    Wsh.Run "msaccess""" & LocalDb & "", WshMaximizedFocus
    Set Wsh = Nothing

to open up and run an Access 97 database.
I get a Run-time 'error' -2147024894 error:  Automation error: the System cannot find file specified.
with the highlight on Wsh.Run "msaccess""" & LocalDb & "", WshMaximizedFocus

When I do a print LocalDb, I get:

When I do a print Dir(LocalDb), I get:

When I go to Windows Explorer and click on all the folders and subfolders - I can see the file present.

All I want to do is run this .mdb database.  There is a form startup that runs all kinds of macros...I even took off the startup form and it still does not see it.  The .mdb database is not read-only nor is the folder.
It's just real frustrating that its there and not working.
Is there another set of code that I can use in Visual Basic to make this access database pull and run?
Thank you in advance for all replies.
1 Solution
Hi stephenlecomptejr,
I think the problem could be that it can't find MSAccess (at least in the path). What you can do is shell directly to the MDB-file, which should start it in access, if it's available. Try:
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
and then
Call ShellExecute(0&, "open", LocalDb, vbNullString, vbNullString, vbMaximizedFocus)
It will act like when you double-click on the file in the explorer. You can use this for any file that has a shell extention for opening it.
stephenlecomptejrAuthor Commented:
thank you, thank you, thank you.

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now