By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,254 Members | 2,365 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,254 IT Pros & Developers. It's quick & easy.

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

P: 9
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
Mar 5 '10 #1

✓ answered by TheSmileyCoder

Assuming the textbox for the EndTime is called tb_EndTime and your button is called btn_SetEndTime then this should work:
Expand|Select|Wrap|Line Numbers
  1. Private Sub btn_SetEndTime_Click()
  2.     Me.tb_EndTime = Now()
  3. 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.

Share this Question
Share on Google+
7 Replies


TheSmileyCoder
Expert Mod 100+
P: 2,321
Assuming the textbox for the EndTime is called tb_EndTime and your button is called btn_SetEndTime then this should work:
Expand|Select|Wrap|Line Numbers
  1. Private Sub btn_SetEndTime_Click()
  2.     Me.tb_EndTime = Now()
  3. 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.
Mar 5 '10 #2

P: 9
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 Images
File Type: jpg Need a time button.jpg (12.5 KB, 478 views)
Mar 5 '10 #3

TheSmileyCoder
Expert Mod 100+
P: 2,321
It should be a command button.
Mar 5 '10 #4

P: 9
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_SetTimeStart_Click()
Me.tb_TimeStart = Now()
End Sub
----------------------------------------------------------

Sorry for the trouble but thank you for the assistance
Attached Images
File Type: jpg Cmdbutton Time Start VB Code.jpg (9.7 KB, 574 views)
File Type: jpg FrmTimeStart.jpg (8.7 KB, 393 views)
File Type: jpg TblTime.jpg (7.5 KB, 396 views)
File Type: jpg Timestart Text Box VB Code view.jpg (11.1 KB, 416 views)
Mar 7 '10 #5

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


Private Sub CmdTimeStart_Click()
Me!TimeStart = Now()
End Sub

Do you see any potential issues using this?

Thanks

Brian
Mar 7 '10 #6

P: 9
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
Mar 7 '10 #7

TheSmileyCoder
Expert Mod 100+
P: 2,321
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.
Apr 13 '10 #8

Post your reply

Sign in to post your reply or Sign up for a free account.