Need to add a button to an Access form to place the time in a table.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bsorensen
    New Member
    • Mar 2010
    • 9

    Need to add a button to an Access form to place the time in a table.

    I have created a Table to track a Name, a project worked on, the amount completed, and the time the project began and ended.

    My input Form to update the above fields allows the user to put their input their name, select their project from a drop down, and enter the amount of work done. I would like to know how I can place 2 buttons on this form which will place a date/time stamp on the current record. One button will go to a "Time Began" field, the second will go to a "Time End" field.

    I have the form setup right now so that there is a time field on it which is currently hidden and this does well at placing the date/time stamp on the table automatically, but I need to make it so it will place it on the table when a button is clicked instead.

    Thank you for any help

    Brian
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    Assuming the textbox for the EndTime is called tb_EndTime and your button is called btn_SetEndTime then this should work:
    Code:
    Private Sub btn_SetEndTime_Click()
        Me.tb_EndTime = Now()
    End Sub
    It does not matter whether the textbox is hidden or not, but it does matter that it is bound to the correct field in your table.

    Comment

    • Bsorensen
      New Member
      • Mar 2010
      • 9

      #3
      Thank you,

      Now I have a new and "Dumber" question: Which type of button is best for this type action? Sorry I know this is a dumb question, but I have now tried using a Command Button, Toggle Button, and options button.

      I was able to get the Toggle Button to work for 2 clicks then it stopped working.

      Sorry I do not typically use buttons like this in my databases, all the button work I have had to handle is basic, add a command button and use the wizard to tell it what to do.

      >TheSmileyOne <--> thank you for the code I knew what to do with it, but I can't find the right type of button to use.

      Thank you for your help and even more for your paitence.

      Attached is a copy of the form I am trying to place a button in, I am at the beginning/test stages of creation so it is rough right now. If I can provide any other information to assist in helping please let me know.

      Brian
      Attached Files
      Last edited by Bsorensen; Mar 5 '10, 10:00 PM. Reason: Added attachment

      Comment

      • TheSmileyCoder
        Recognized Expert Moderator Top Contributor
        • Dec 2009
        • 2322

        #4
        It should be a command button.

        Comment

        • Bsorensen
          New Member
          • Mar 2010
          • 9

          #5
          Thank you, though I still cannot make this work, I have attached shots of the VB Code For the button.

          I even created a new dbase with the sole purpose to test and figure out this button, as I thought maybe something I had done in my blind blundering had "borked" up my other dbase.

          However, In either case I am not able to make it work, I insert the code you provided changed it to fit my field names/textboxes and when I click the button on the form Nothing happens, nothing displays in the TimeStart Box, and nothing displays in the TimeStart Field on the table.

          Here is the code I used(also see the new screen shots)

          --------------------------------------------------------
          Private Sub Command1_SetTim eStart_Click()
          Me.tb_TimeStart = Now()
          End Sub
          ----------------------------------------------------------

          Sorry for the trouble but thank you for the assistance
          Attached Files

          Comment

          • Bsorensen
            New Member
            • Mar 2010
            • 9

            #6
            After a few hours of blindly testing this is the coding I came up with which works:


            Private Sub CmdTimeStart_Cl ick()
            Me!TimeStart = Now()
            End Sub

            Do you see any potential issues using this?

            Thanks

            Brian

            Comment

            • Bsorensen
              New Member
              • Mar 2010
              • 9

              #7
              What is the difference/benefits or evils of using a (.) versus a (!) in the coding?

              Smiley Noted in his to use a (.) after ME:

              Me.tb_TimeStart = Now()

              I was able to get it to work using a (!):

              Me!TimeStart = Now()

              I went back later in my tinkering and it also works with the period as Smiley had used.

              So which is better to use and why?

              Thank you

              Brian

              Comment

              • TheSmileyCoder
                Recognized Expert Moderator Top Contributor
                • Dec 2009
                • 2322

                #8
                I don't really know if there is any coding difference.

                I tried using ! and . and what I did notice is that the VBA editor will come with suggestions (for properties/methods) when I use the . and not when I use the !

                I've always used . myself.

                Comment

                Working...