none
VBA code to check if an application is open.

    Question

  • If I am running an access program accdb, while running, I have another program to replace the file (for updating), this can cause error.

    I would like to know how can we use the VBA code to check if the file is open, so that I can warn the user to close it before updating.

    Thank you.

     


    TS Lim
    Sunday, August 14, 2011 7:36 AM

Answers

  • I found a solution, to use Name to trap for an error.

    If my project is at C:\myproject.accdr then I use the Name statment as follows:

    Name "C:\myproject.accdr"  As "C:\myproject.accdr"

    With the error, I will stop code to update the file.

    This is not a fool-proof solution, If the user move the file to other location, tben it will not work.

     


    TS Lim
    • Marked as answer by Macy Dong Monday, August 22, 2011 3:47 AM
    Sunday, August 14, 2011 9:38 AM
  • TS Lim wrote:

    If I am running an access program accdb, while running, I have another program to replace the file (for updating), this can cause error.

    Also check the last section at http://autofeupdater.com/pages/faqb.htm
    for alternatives.   Note the Auto FE Updater can also perform this task
    as well as many other related functions.

    Tony


    Tony Toews, Microsoft Access MVP
    Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
    Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
    For a convenient utility to keep your users FEs and other files   updated see http://www.autofeupdater.com/

    • Marked as answer by Macy Dong Monday, August 22, 2011 3:47 AM
    Sunday, August 14, 2011 10:04 AM
  • It is possible to check the active process that are running the same way you would if you were manually checking the process in the task manager.  In VBA you can run any DLL program in the Windows\System32 folder.  I've done this myself a long time ago.  You can use the user32.dll library to check all the active processes and get the handle of any process.  Th SHELL VBA function returns the handle and then using functions in the user32.dll get the parent or children of the process.

    You would have to define any DLL functions using the VBA statement "Declare Function" like the sample below.

    Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Integer, ByVal lpdwProcessId As Integer) As Integer

    here are a few webpages you may want to look at which list some of the functions avaialble using the Windows API library functions

    http://msdn.microsoft.com/en-us/library/aa302340.aspx

    http://msdn.microsoft.com/en-us/library/ff468919(v=VS.85).aspx

    http://support.microsoft.com/kb/190000

     


    jdweng
    • Marked as answer by Macy Dong Monday, August 22, 2011 3:47 AM
    Sunday, August 14, 2011 4:49 PM
  • You can give a  try to WMI. http://msdn.microsoft.com/en-us/library/aa394599(v=VS.85).aspx

     

    You may need to have the rights (priviledges) to satisfy enforced security requirements.

     

     

    • Marked as answer by Macy Dong Monday, August 22, 2011 3:47 AM
    Monday, August 15, 2011 4:58 PM

All replies

  • I found a solution, to use Name to trap for an error.

    If my project is at C:\myproject.accdr then I use the Name statment as follows:

    Name "C:\myproject.accdr"  As "C:\myproject.accdr"

    With the error, I will stop code to update the file.

    This is not a fool-proof solution, If the user move the file to other location, tben it will not work.

     


    TS Lim
    • Marked as answer by Macy Dong Monday, August 22, 2011 3:47 AM
    Sunday, August 14, 2011 9:38 AM
  • TS Lim wrote:

    If I am running an access program accdb, while running, I have another program to replace the file (for updating), this can cause error.

    Also check the last section at http://autofeupdater.com/pages/faqb.htm
    for alternatives.   Note the Auto FE Updater can also perform this task
    as well as many other related functions.

    Tony


    Tony Toews, Microsoft Access MVP
    Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
    Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
    For a convenient utility to keep your users FEs and other files   updated see http://www.autofeupdater.com/

    • Marked as answer by Macy Dong Monday, August 22, 2011 3:47 AM
    Sunday, August 14, 2011 10:04 AM
  • It is possible to check the active process that are running the same way you would if you were manually checking the process in the task manager.  In VBA you can run any DLL program in the Windows\System32 folder.  I've done this myself a long time ago.  You can use the user32.dll library to check all the active processes and get the handle of any process.  Th SHELL VBA function returns the handle and then using functions in the user32.dll get the parent or children of the process.

    You would have to define any DLL functions using the VBA statement "Declare Function" like the sample below.

    Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Integer, ByVal lpdwProcessId As Integer) As Integer

    here are a few webpages you may want to look at which list some of the functions avaialble using the Windows API library functions

    http://msdn.microsoft.com/en-us/library/aa302340.aspx

    http://msdn.microsoft.com/en-us/library/ff468919(v=VS.85).aspx

    http://support.microsoft.com/kb/190000

     


    jdweng
    • Marked as answer by Macy Dong Monday, August 22, 2011 3:47 AM
    Sunday, August 14, 2011 4:49 PM
  • You can give a  try to WMI. http://msdn.microsoft.com/en-us/library/aa394599(v=VS.85).aspx

     

    You may need to have the rights (priviledges) to satisfy enforced security requirements.

     

     

    • Marked as answer by Macy Dong Monday, August 22, 2011 3:47 AM
    Monday, August 15, 2011 4:58 PM