One last command before DB closes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark R

    #1

    One last command before DB closes

    Hi Guru's,
    I have a frontend application where my boss wants to when people are
    using the database.
    I have a form which OnOpen, inserts the username, network login and
    date/time it was opened to a table.
    I have created a 'Close' button which when clicked, updates the 'Logged_out'
    time and then quits the application. My problem is that when users click on
    the cross (top right corner) to close the database, this time is not logged.

    Is there a way in which I can still log the time even when they click on the
    application close button or a way in which I can hide the close button so
    that the only way the application can be shut down is via my close button?

    TIA

    Mark


  • MacDermott

    #2
    Re: One last command before DB closes

    One common approach to this problem is to have a small form (its visible
    property can even be set to False) which opens on startup and remains open
    throughout the time the application is open. Closing Access causes this
    form to close, so code in its Close event executes. Put your "logout" code
    there.

    HTH
    - Turtle

    "Mark R" <mark.reed75@nt lworld.com> wrote in message
    news:XHlVc.200$ Rw4.88@newsfe2-gui.ntli.net...[color=blue]
    > Hi Guru's,
    > I have a frontend application where my boss wants to when people are
    > using the database.
    > I have a form which OnOpen, inserts the username, network login and
    > date/time it was opened to a table.
    > I have created a 'Close' button which when clicked, updates the[/color]
    'Logged_out'[color=blue]
    > time and then quits the application. My problem is that when users click[/color]
    on[color=blue]
    > the cross (top right corner) to close the database, this time is not[/color]
    logged.[color=blue]
    >
    > Is there a way in which I can still log the time even when they click on[/color]
    the[color=blue]
    > application close button or a way in which I can hide the close button so
    > that the only way the application can be shut down is via my close button?
    >
    > TIA
    >
    > Mark
    >
    >[/color]


    Comment

    • Pieter Linden

      #3
      Re: One last command before DB closes

      "Mark R" <mark.reed75@nt lworld.com> wrote in message news:<XHlVc.200 $Rw4.88@newsfe2-gui.ntli.net>.. .[color=blue]
      > Hi Guru's,
      > I have a frontend application where my boss wants to when people are
      > using the database.
      > I have a form which OnOpen, inserts the username, network login and
      > date/time it was opened to a table.
      > I have created a 'Close' button which when clicked, updates the 'Logged_out'
      > time and then quits the application. My problem is that when users click on
      > the cross (top right corner) to close the database, this time is not logged.
      >
      > Is there a way in which I can still log the time even when they click on the
      > application close button or a way in which I can hide the close button so
      > that the only way the application can be shut down is via my close button?
      >
      > TIA
      >
      > Mark[/color]
      Lemme see if I remember the answer to this one.... open a hidden form
      when the database starts up, and then have it write to the Logins
      table. Then when the user logs out, grab his login from today, update
      it with the logout, and update the record in the Form's close event.

      Comment

      • Craig W.

        #4
        Re: One last command before DB closes

        Use the Unload event in Access...

        http://msdn.microsoft.com/library/de...cevtUnload.asp

        I created a blank database, added a "close" button and a displayed a
        message saying that button was clicked. I also tossed a message box
        into the Form Unload event saying the form is being unloaded. When
        you click the button both message boxes show up... when you close the
        database (by clicking the X or Cross not the button on the form) it
        just displays the unload event message box.

        - Craig

        "Mark R" <mark.reed75@nt lworld.com> wrote in message news:<XHlVc.200 $Rw4.88@newsfe2-gui.ntli.net>.. .[color=blue]
        > Hi Guru's,
        > I have a frontend application where my boss wants to when people are
        > using the database.
        > I have a form which OnOpen, inserts the username, network login and
        > date/time it was opened to a table.
        > I have created a 'Close' button which when clicked, updates the 'Logged_out'
        > time and then quits the application. My problem is that when users click on
        > the cross (top right corner) to close the database, this time is not logged.
        >
        > Is there a way in which I can still log the time even when they click on the
        > application close button or a way in which I can hide the close button so
        > that the only way the application can be shut down is via my close button?
        >
        > TIA
        >
        > Mark[/color]

        Comment

        • Mark R

          #5
          Re: One last command before DB closes

          Thanks for the suggestion, however, The main form is open all the time and
          the "logout" code is in the "OnClose" property of this form. The problem I
          have is when the Db is opened, the user sees a login form. The user then
          enters their login and password. When they click on a command button the
          username is appended to a temp table within the frontend and in the logging
          table within the backend (along with date/time opened).
          As there may be several users at any time, the time logged out needs to be
          reference with the current user. This is done by having a bound text box on
          the main form to the temp table within the frontend. The "OnClose" command
          is:
          Private Sub Form_Close()
          'record the time at which users logged out
          On Error GoTo err_form_close

          DoCmd.SetWarnin gs False
          DoCmd.RunSQL "UPDATE user_logging SET user_logging.Ou t = Now() WHERE
          (((user_logging .Out) Is Null) AND ((user_logging. Form)='Main Menu') AND
          ((user_logging. username)= forms!master_pa ge!userid));"

          'delete the current user field
          DoCmd.RunSQL "delete * from current_user;"

          exit_form_close :
          Exit Sub

          err_form_close:
          MsgBox Err.Description
          Resume exit_form_close
          End Sub

          If the form is closed before the app is quit then there is not problem but
          if the app is quit before the form is closed, the form loses the value and
          then the user id prompted for forms!master_pa ge!userid.

          I hope I have explained this ok?

          Mark

          "MacDermott " <macdermott@nos pam.com> wrote in message
          news:zCpVc.2988 0$nx2.15257@new sread2.news.atl .earthlink.net. ..[color=blue]
          > One common approach to this problem is to have a small form (its visible
          > property can even be set to False) which opens on startup and remains open
          > throughout the time the application is open. Closing Access causes this
          > form to close, so code in its Close event executes. Put your "logout"[/color]
          code[color=blue]
          > there.
          >
          > HTH
          > - Turtle
          >
          > "Mark R" <mark.reed75@nt lworld.com> wrote in message
          > news:XHlVc.200$ Rw4.88@newsfe2-gui.ntli.net...[color=green]
          > > Hi Guru's,
          > > I have a frontend application where my boss wants to when people are
          > > using the database.
          > > I have a form which OnOpen, inserts the username, network login and
          > > date/time it was opened to a table.
          > > I have created a 'Close' button which when clicked, updates the[/color]
          > 'Logged_out'[color=green]
          > > time and then quits the application. My problem is that when users click[/color]
          > on[color=green]
          > > the cross (top right corner) to close the database, this time is not[/color]
          > logged.[color=green]
          > >
          > > Is there a way in which I can still log the time even when they click on[/color]
          > the[color=green]
          > > application close button or a way in which I can hide the close button[/color][/color]
          so[color=blue][color=green]
          > > that the only way the application can be shut down is via my close[/color][/color]
          button?[color=blue][color=green]
          > >
          > > TIA
          > >
          > > Mark
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • MacDermott

            #6
            Re: One last command before DB closes

            Two possibilities you might try:
            Use the Form_Unload event, rather than Form_Close.
            Store the UserName in a global variable, rather than a textbox on the
            form.

            HTH
            - Turtle

            "Mark R" <mark.reed75@nt lworld.com> wrote in message
            news:yfrVc.261$ Nq1.184@newsfe6-gui.ntli.net...[color=blue]
            > Thanks for the suggestion, however, The main form is open all the time and
            > the "logout" code is in the "OnClose" property of this form. The problem I
            > have is when the Db is opened, the user sees a login form. The user then
            > enters their login and password. When they click on a command button the
            > username is appended to a temp table within the frontend and in the[/color]
            logging[color=blue]
            > table within the backend (along with date/time opened).
            > As there may be several users at any time, the time logged out needs to be
            > reference with the current user. This is done by having a bound text box[/color]
            on[color=blue]
            > the main form to the temp table within the frontend. The "OnClose" command
            > is:
            > Private Sub Form_Close()
            > 'record the time at which users logged out
            > On Error GoTo err_form_close
            >
            > DoCmd.SetWarnin gs False
            > DoCmd.RunSQL "UPDATE user_logging SET user_logging.Ou t = Now() WHERE
            > (((user_logging .Out) Is Null) AND ((user_logging. Form)='Main Menu') AND
            > ((user_logging. username)= forms!master_pa ge!userid));"
            >
            > 'delete the current user field
            > DoCmd.RunSQL "delete * from current_user;"
            >
            > exit_form_close :
            > Exit Sub
            >
            > err_form_close:
            > MsgBox Err.Description
            > Resume exit_form_close
            > End Sub
            >
            > If the form is closed before the app is quit then there is not problem but
            > if the app is quit before the form is closed, the form loses the value and
            > then the user id prompted for forms!master_pa ge!userid.
            >
            > I hope I have explained this ok?
            >
            > Mark
            >
            > "MacDermott " <macdermott@nos pam.com> wrote in message
            > news:zCpVc.2988 0$nx2.15257@new sread2.news.atl .earthlink.net. ..[color=green]
            > > One common approach to this problem is to have a small form (its visible
            > > property can even be set to False) which opens on startup and remains[/color][/color]
            open[color=blue][color=green]
            > > throughout the time the application is open. Closing Access causes this
            > > form to close, so code in its Close event executes. Put your "logout"[/color]
            > code[color=green]
            > > there.
            > >
            > > HTH
            > > - Turtle
            > >
            > > "Mark R" <mark.reed75@nt lworld.com> wrote in message
            > > news:XHlVc.200$ Rw4.88@newsfe2-gui.ntli.net...[color=darkred]
            > > > Hi Guru's,
            > > > I have a frontend application where my boss wants to when people[/color][/color][/color]
            are[color=blue][color=green][color=darkred]
            > > > using the database.
            > > > I have a form which OnOpen, inserts the username, network login and
            > > > date/time it was opened to a table.
            > > > I have created a 'Close' button which when clicked, updates the[/color]
            > > 'Logged_out'[color=darkred]
            > > > time and then quits the application. My problem is that when users[/color][/color][/color]
            click[color=blue][color=green]
            > > on[color=darkred]
            > > > the cross (top right corner) to close the database, this time is not[/color]
            > > logged.[color=darkred]
            > > >
            > > > Is there a way in which I can still log the time even when they click[/color][/color][/color]
            on[color=blue][color=green]
            > > the[color=darkred]
            > > > application close button or a way in which I can hide the close button[/color][/color]
            > so[color=green][color=darkred]
            > > > that the only way the application can be shut down is via my close[/color][/color]
            > button?[color=green][color=darkred]
            > > >
            > > > TIA
            > > >
            > > > Mark
            > > >
            > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • Mark R

              #7
              Re: One last command before DB closes

              Thanks all, I moved the code to OnUnload and it works fine.

              Cheers all,

              Mark

              "Mark R" <mark.reed75@nt lworld.com> wrote in message
              news:XHlVc.200$ Rw4.88@newsfe2-gui.ntli.net...[color=blue]
              > Hi Guru's,
              > I have a frontend application where my boss wants to when people are
              > using the database.
              > I have a form which OnOpen, inserts the username, network login and
              > date/time it was opened to a table.
              > I have created a 'Close' button which when clicked, updates the[/color]
              'Logged_out'[color=blue]
              > time and then quits the application. My problem is that when users click[/color]
              on[color=blue]
              > the cross (top right corner) to close the database, this time is not[/color]
              logged.[color=blue]
              >
              > Is there a way in which I can still log the time even when they click on[/color]
              the[color=blue]
              > application close button or a way in which I can hide the close button so
              > that the only way the application can be shut down is via my close button?
              >
              > TIA
              >
              > Mark
              >
              >[/color]


              Comment

              Working...