Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2003
    Posts
    3

    Question Unanswered: Launching Access using Visual Basic

    I am using a little VB6 program that compares the versions between a local Access 2000 database and one on the server. If the server version is greater this file is copied locally and then MSAccess is launched. The problem that I am having is that I now need this to work on Windows XP but the path to MSaccess.exe is different to Win2000 so the shell command is failing.

    In the short term I have fixed the problem by adding an 'If...Then' clause but I was wondering if there is some generic code that I can use in VB to locate the full path for MSAccess.exe so that I can shell to it from any OS.

    In Access VBA I could have used SysCmd(acSysCmdAccessDir) so I'm hoping for a VB6 equivalent to this.

    Thanks for all the help.

  2. #2
    Join Date
    Nov 2002
    Location
    San Francisco
    Posts
    251

    Re: Launching Access using Visual Basic

    you can have installed Access97, Access2000 and AccessXP on one machine (as I do), so you should rather run MSACCESS.exe instead of pointing to directory....

    try this:

    DestinationFile = "C:\Temp\Database.mdb"
    RunThis = "Msaccess.exe " & Chr(34) & DestinationFile & Chr(34)

    Set WshShell = CreateObject("WScript.Shell")
    WshShell.Run RunThis, 3, False


    i used in SCRIPT



    jiri

  3. #3
    Join Date
    Jan 2003
    Location
    Dordrecht, The Netherlands
    Posts
    95

    Re: Launching Access using Visual Basic

    You might use the Access library by referencing the "Microsoft Access 9.0 Library" which should be visible if Office 2000 has been installed on the PC where you run VB6 on. On my PC it is 10.0 because I use Office XP.

    You could then use a piece of code like this:


    Sub Test()
    Dim appAccess As Access.Application

    Set appAccess = New Access.Application
    appAccess.Visible = True
    appAccess.OpenCurrentDatabase "D:\Ad\Werk\RBO.adp"

    'Do your stuff by using the Access object-model

    appAccess.Quit
    End Sub

  4. #4
    Join Date
    Jan 2003
    Posts
    3

    Re: Launching Access using Visual Basic

    Thanks for the response. I've used this WshShell object in Visual Basic scripting but I can't seem to get it to work using VB6. I tried your code but I keep getting an error:

    Run-time error ‘-2147024894 (80070002)’:
    Method ‘Run’ of object ‘IwshShell2’ failed

    Am I forgetting something?

  5. #5
    Join Date
    Jan 2003
    Posts
    3

    Re: Launching Access using Visual Basic

    Thanks Ad Dieleman. I tried this but get the error:

    Run-time error ‘429’:
    ActiveX component can’t create object

    when it reaches the line:
    Set appAccess = New Access.Application

    I check the references and they seem to be fine.

    Any ideas?

    (P.S. Forgive my ignorance)

  6. #6
    Join Date
    Jan 2003
    Location
    Dordrecht, The Netherlands
    Posts
    95
    I never encountered this error with Access or any other Office-application. The only suggestion I can offer is to reinstall Office.

    Good luck.

    Ad Dieleman.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •