open a Access database with VBA

Discussion in 'Microstation' started by Alexander Heide, May 18, 2004.

  1. Hi Group!

    If i run following code i receive message

    "Error '53'"
    "File not found"

    But file "House3.mdb" is there. What is wrong?

    My code:

    Sub OpenDatabaseFile()
    Dim strFile as String
    Dim strDataPath as String
    Dim strdefault As String
    Dim RetVal

    strDataPath = Application.ActiveDesignFile.Path
    strdefault = InStrRev(strDataPath, "Projects")
    If strdefault > 0 Then
    strDataPath = Left$(strDataPath, strdefault - 1)& "Data\House3.mdb"
    End If

    strFile = "strDataPath"
    RetVal = Shell(strFile, 1)
    End Sub



    Thank You!
    Alexander
     
    Alexander Heide, May 18, 2004
    #1
  2. Alexander Heide

    AHA Guest

    Just an idea. Print the contents of the resulting filename ("strDataPath") to
    screen, so you can verify it is pointing to where you think it should be.

    Alex

    "Alexander Heide" <> schreef in bericht
    | Hi Group!
    |
    | If i run following code i receive message
    |
    | "Error '53'"
    | "File not found"
    |
    | But file "House3.mdb" is there. What is wrong?
    |
    | My code:
    |
    | Sub OpenDatabaseFile()
    | Dim strFile as String
    | Dim strDataPath as String
    | Dim strdefault As String
    | Dim RetVal
    |
    | strDataPath = Application.ActiveDesignFile.Path
    | strdefault = InStrRev(strDataPath, "Projects")
    | If strdefault > 0 Then
    | strDataPath = Left$(strDataPath, strdefault - 1)&
    "Data\House3.mdb"
    | End If
    |
    | strFile = "strDataPath"
    | RetVal = Shell(strFile, 1)
    | End Sub
    |
    |
    |
    | Thank You!
    | Alexander
     
    AHA, May 18, 2004
    #2
  3. Alexander Heide

    Jon Summers Guest

    Alexander ...
    1 The Shell() function attempt to run an executable
    2 A .mdb file is a data file

    You can't execute a data file. VBA does not perform magic: it can't run a
    data file. If you want to understand the limits of Shell(), open a
    command window and enter the line you want to execute. In this case:
    C:\Program Files\Bentley\Program\MicroStation\Data\House3.mdb
     
    Jon Summers, May 19, 2004
    #3
  4. Hi "AHA"!

    Thanks for answer!

    Debug.Print delivers the right path!!!
    That is so curiouse!
    And the file is also in the right folder.

    Greetings
    AHeide
     
    Alexander Heide, May 19, 2004
    #4
  5. Alexander Heide

    GeoffH Guest

    However, if there is an association between an MDB file and MS Access, the
    above command you suggest *should* start up MS Access and open the
    House3.mdb database, as desired.

    GeoffH
     
    GeoffH, May 20, 2004
    #5
  6. Alexander Heide

    Tim Arheit Guest

    Yes and no. Shell() ignores any associations. Your options are to
    either use the ShellExecute API (which does use associations) or to
    use the command line. ie.

    RetVal = Shell("cmd /c " & strFile,1)

    or (under windows 95/98):
    RetVal = Shell("command /c " & strFile,1)


    -Tim
     
    Tim Arheit, May 20, 2004
    #6
  7. Alexander Heide

    GeoffH Guest

    I was referring to the "open a command window" Jon was suggesting, because
    it *will* start up MS Access.

    GeoffH
    http://home.comcast.net/~hksys/
     
    GeoffH, May 21, 2004
    #7
  8. Alexander Heide

    Jon Summers Guest

    Geoff ...
    Yes, it was a bad example because the Windows Explorer file association
    will perform the magic. I was hoping to illustrate the difference between
    running an executable and attempting to run a data file. Next time, I'll
    be more careful 8-(
     
    Jon Summers, May 23, 2004
    #8
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 (here). After that, you can post your question and our members will help you out.