• Detect whether program already running

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Detect whether program already running

    Author
    Topic
    #356737

    Hi Access programmers:
    Is there a way to detect at startup whether my Access program is already running and, if so, display a message and shut down. Gotta’ feeling this is an API function with window handles (hwnd) and horrible stuff like that.
    Thanks,
    Gwenda

    Viewing 1 reply thread
    Author
    Replies
    • #528643

      The attatched dll should be of assistance. Declare a function as below and call some sort of startup routine when you start Access.

      ‘This dll should be in the system directory so that it can always be found
      Declare Function TestAndActivate Lib “AndySoft_AccessStart.dll” (ByVal hwnd As Long) As Long

      public function Startup()
      If TestAndActivate(Application.hWndAccessApp) = 0 Then
      Application.Quit
      Else
      …..

      • #528705

        Andy,
        Can’t thank you enough. Will be testing it out shortly.
        If you ever come to beautiful Vancouver, I owe you lunch.
        Gwenda joy

      • #528843

        Hi Andy,
        I’m chicken … afraid of calling your DLL in my Access program. Don’t I have to register your DLL first?
        Gwenda

        • #528867

          Hi Gwenda,
          Some dll’s are registered so that information is stored in the registry to allow them to run. (Maybe other reasons as well). If a dll needds registering you should only get an error when you try to use it and it has not yet been registered. This little dll just needs to be in a directory that the op system looks in for searching for dll’s / exe’s. Typically the windows/system directory is used for this. Then just declare the function in code and call it somewhere in your startup procedure. If you experience any problems let me know.

          A comment to everyone else. I know Microsoft do not recommend putting dll’s in the Windows or System directories. Putting the dll in another directory may require having to register it (or at least more coding somewhere).

        • #528952

          Hi Gwenda,
          Please throw away the first dll I posted. I had stripped too much out of the functional version I based it on. You require the one attatched here. Also I didn’t make it clear in the origninal post that the declare should be in a module, not in a form.

          Thanks for the offer of lunch, I’ll have to pass on it. I doubt I will ever visit Canada.

    • #528666

      Hi Gwenda
      Your horrible feeling is absolutely spot on!
      Follow this link to Dev Ashish’s excellent site
      http://www.mvps.org/access/api/api0041.htm
      (if you are after testing for Access running)
      (There is another page for testing for any application running)
      The use of it is quite well explained for an API call!
      HTH

      • #528706

        Hi Steve,
        Would that be the Scottish flag you’re flying??? Did you see the post from Andy? I’m going to try his DLL, but thanks for the steer to the Dev Ashish’s site. As I said to Andy, if you’re even in beautiful Vancouver, I’ll buy you lunch.
        Gwenda

        • #528801

          English actually! (St George and all that)
          I did see Andy’s post about the DLL. I haven’t got involved with DLLs yet. I think you need to have them installed/registered with the associated problems re distribution/permissions. I like to keep my dbs ‘in one piece’ where possible.
          I stand to be corrected/educated though!

          • #528842

            Ahhh… English! Now I understand why your signature is a tankard of beer.

            I haven’t tried Andy’s DLL yet for exactly that reason … I’m not sure how to install/register and distribute it. I’ll ask Andy.
            G

    Viewing 1 reply thread
    Reply To: Detect whether program already running

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: