Announcement

Collapse

New Sub-Forum

In an effort to help make sure there are appropriate categories for topics of discussion that are happening, there is now a sub-forum for databases and database programming under Special Interest groups. Please direct questions, etc., about this topic to that sub-forum moving forward. Thank you.
See more
See less

Scheduled Reminder

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Scheduled Reminder

    schedule reminder

    An MS Access database is updated each evening at 12:15AM and all users have to be out of the database at that time. The users access the database through a UserApp that I maintain, and I want to add a feature to the program that will remind them at 11:55PM to close their program in ten minutes. Then if they are still in the program at 12:14AM I intend to tell them the program will close in 15 seconds. I need help identifying the most efficient way to know if the program is running at 11:55PM and 12:14AM. Do you have suggestions for me?

    Thank you in advance,

    Ken

  • #2
    Use Windows scheduled tasks to run a program you write that looks for the
    applicable window and if found gives a message box reminding them.
    or simply a message box at the appropriate time
    Last edited by Fred Buffington; 15 Dec 2007, 05:08 PM.
    Client Writeup for the CPA

    buffs.proboards2.com

    Links Page

    Comment


    • #3
      Fred,

      That will work for the reminders, at least the first one, but if the second reminder came from the program then it would be easy to close the program if they don't.

      Ken

      Comment


      • #4
        Put the shutdown messages in a file on the server.

        In the app, use a timer to check the contents of the file every 30 secs.
        If not null, pop up a modeless warning window. If the contents of the message indicate that shutdown is imminent, prevent the user from starting a new transaction.

        Comment


        • #5
          If all access to the database goes through your program, you already know who / what is running?
          Regards,
          Peter

          Comment


          • #6
            Have your program create a mutex object, and your scheduled program check for its existence. If it exists, the program is running.

            If you want to be mean about it, you could write a little program which runs on each user system which in its entirety looks like ...
            Code:
            $MUTEX_NAME =  "ABCDEFGH" 
            
            FUNCTION PbMain () AS LONG
            DO 
               hMutex = OpenMutex (%MUTEX_ALL_ACCESS, %FALSE, $MUTEX_NAME)
               If ISTRUE hMutex THEN        ' mutex object exists, program is running
                 MSGBOX "Hey, end your program and click OK!"
                 CloseHandle  hMutex 
                 ITERATE DO    ' try again
               ELSE  ' program not running,  user is permitted to exit 
                 EXIT DO
               END IF
            LOOP
            
            END FUNCTION  ' PbMain
            MCM
            Michael Mattias
            Tal Systems Inc. (retired)
            Racine WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Oh. I missed this...my bad...
              and I want to add a feature to the program that will remind them at 11:55PM to close their program in ten minutes. ...
              I think what you might find perfect for this is ...
              (CORRECTED LINK 12-18-07)
              Waitable Timer Object Demo June 2005


              Just set up the WT object when the program starts and use a separate thread of execution to wait for that to happen... just exactly as shown in the demo!

              (And you can even set up a "Mister Meanie" loop when the timer fires!)

              MCM
              Last edited by Michael Mattias; 18 Dec 2007, 08:21 AM. Reason: Corrected link to point to re-post
              Michael Mattias
              Tal Systems Inc. (retired)
              Racine WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Wow, I just looked at that linked demo. Did the forum software conversion cheese that up or what?

                Let me post a fresh version as a reply and erase the first post.

                Well, I could not erase or edit the original, but the last post is a re-tested and re-posted version.

                USE POST #3, not POST #1

                MCM
                Last edited by Michael Mattias; 16 Dec 2007, 10:18 AM. Reason: Added comment re re-post mission accomplished.
                Michael Mattias
                Tal Systems Inc. (retired)
                Racine WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  Well, in spite of the best efforts of the webmaster (seriously, he tried), the result of attempting to fix up the old post were fruitless, and the 'fix' was to just re-post it, so I did:
                  Waitable Timer Object Demo June 2005

                  MCM
                  Michael Mattias
                  Tal Systems Inc. (retired)
                  Racine WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    Thanks, for the suggestions. I used a WaitableTimer. Below is the relevant part of the code.

                    Code:
                        SELECT CASE message
                    
                           CASE %WM_Create
                    
                               OPEN "LogFile.txt" FOR OUTPUT AS #3
                               
                               If Timer < 15 * 60 Then
                                  MsgBox "User App will not open between 12:00 Midnight and 12:15AM",0,"Warning"
                                  DestroyWindow hWnd
                               End if
                    
                               hTimer = SetTimer(hWnd, BYVAL &H0000FEED, 3000, BYVAL %NULL)
                               Print #3, "hTimer 0"+str$(hTimer)
                    
                           CASE %WM_TIMER
                              Print #3, "hTimer 1"+str$(hTimer)
                              PassData.hWnd = hWnd
                              dwData = VarPtr(PassData)
                              Thread Create ShutDown(dwData) TO hThread
                              THREAD CLOSE hThread TO nThResult
                              txt = "Checking on thread "+STR$(hThread)+"  "+STR$(nThResult)
                              Print #3, txt
                              KillTimer hWnd, hTimer
                              Print #3, "hTimer 2"+str$(hTimer)
                    
                           Case %UserMsg2
                              jPtr = wParam
                              j = @jPtr
                              If j = 1 Then
                                 Call ShutDownMsg(hWnd)
                              Elseif j = 2 Then
                                 Call CloseUserApp(hWnd)
                              Elseif j = 3 Then
                                 DestroyWindow hWnd
                              End if
                    
                           CASE %WM_DESTROY
                                If PassData.hEvent Then
                                   Print #3, "PassData.hEvent ";PassData.hEvent
                                   CloseHandle PassData.hEvent
                                End if
                    
                    '=======================================================================
                    Function ShutDown(ByVal dwData as dword) as long
                        'LOCAL hEvent      AS LONG
                        LOCAL firetime      AS QUAD, isPeriodic AS LONG, bManualReset AS LONG
                        LOCAL Qptr            AS QUAD  PTR
                        LOCAL ft AS FILETIME,  localt AS SYSTEMTIME
                        LOCAL LocalFt AS FILETIME
                        Local nResult as long, jPtr as long ptr, j as long, nWfso as long
                        Local PdPtr as PassDataType Ptr
                        
                           PdPtr = dwData
                    
                           ' create an unnamed waitable timer object
                           ' param 1 = security attributes, not used; param 3=object name or NULL for unnamed object
                           bManualReset  = %TRUE
                           @PdPtr.hEvent     =  CreateWaitableTimer (BYVAL %NULL, bManualReset, BYVAL %NULL)
                           ' Set the timer. Uses FILETIME structure (UTC time).
                           ' 1 filetime unit = 100ns
                           GetLocalTime              LocalT
                           Print #3, "LocalTime "; LocalT.wyear, LocalT.wMonth, LocalT.wDay,  LocalT.wHour,  LocalT.wMinute,  LocalT.wSecond,_
                                       "@PdPtr.hEvent ";@PdPtr.hEvent
                    
                           LocalT.wHour          = 23
                           LocalT.wMinute        = 45
                           LocalT.wSecond        = 0
                           SystemTimeToFileTime       LocalT, LocalFt
                           LocalFileTimeToFileTime    LocalFt, ft
                           Qptr                      =  VARPTR(ft)                   ' read filetime as quad integer
                           firetime                 = @Qptr    ' + (30 * 1.0E7)   ' convert 100-nanoseconds to seconds and add
                           IsPeriodIc   = %FALSE                      ' it's a one-time timer object
                           nResult      = SetWaitableTimer (@PdPtr.hEvent, BYREF Firetime, IsPeriodic, BYVAL %NULL, BYVAL %NULL, BYVAL %NULL)
                                        ' params 3-4: when using callback procedure. Param 5 Win 2000+ only.
                           nWfso = WaitForSingleObject  @PdPtr.hEvent, %Infinite
                           Print #3, "WFSO return value = "+str$(nWfso)'a value of zero indicates that the event terminated the wait
                           j = 1
                           jPtr = VarPtr(j)
                           SendMessage @PdPtr.hWnd, %UserMsg2, jPtr, 0
                    
                           firetime                 = @Qptr + (14*60 * 1.0E7)   ' convert 100-nanoseconds to seconds and add
                           nResult      = SetWaitableTimer (@PdPtr.hEvent, BYREF Firetime, IsPeriodic, BYVAL %NULL, BYVAL %NULL, BYVAL %NULL)
                                        ' params 3-4: when using callback procedure. Param 5 Win 2000+ only.
                           nWfso = WaitForSingleObject  @PdPtr.hEvent, %Infinite
                           j = 2
                           SendMessage @PdPtr.hWnd, %UserMsg2, jPtr, 0
                    
                           firetime                 = FireTime + (15 * 1.0E7)   ' convert 100-nanoseconds to seconds and add
                           nResult      = SetWaitableTimer (@PdPtr.hEvent, BYREF Firetime, IsPeriodic, BYVAL %NULL, BYVAL %NULL, BYVAL %NULL)
                                        ' params 3-4: when using callback procedure. Param 5 Win 2000+ only.
                           nWfso = WaitForSingleObject  @PdPtr.hEvent, %Infinite
                           j = 3
                           GetLocalTime              LocalT
                           Print #3, "LocalShutDownTime "; LocalT.wyear, LocalT.wMonth, LocalT.wDay,  LocalT.wHour,  LocalT.wMinute,  LocalT.wSecond
                           SendMessage @PdPtr.hWnd, %UserMsg2, jPtr, 0
                    
                    End Function

                    Comment


                    • #11
                      It is so nice to hear someone actually used something you posted.

                      Thanks for taking the time to let me know.
                      Michael Mattias
                      Tal Systems Inc. (retired)
                      Racine WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment

                      Working...
                      X