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

Recording the Time Automatically into a Table from a Form

P: 3
Greetings,
I need to brush up on my somewhat rusty Access skills. The problem I face is a very elementary one but for the life of me I cannot figure out how to solve it.

A form in my database needs to record the time a user adds a record and update this in the relevant table. I have created a textbox in the form which is bound to the associated field in the table. This textbox is hidden the locked, so the user will not be able to see or use it.

I am trying to display the time in this textbox when a command button is clicked. Since this textbox is bound to the relevant field in the table, that updates when the textbox's value changes. My textbox is "EntryTime", my command button "Save". Here's the code I currently have:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Save_Click()
  2. EntryTime.Text = Time
  3. End Sub
  4.  
This gives me the error "Runtime error 2185: You can't reference a property or method for a control unless the control has the focus". I have tried different variations on my code, but cannot get past this error.

I would greatly appreciate it if someone can shed some light on this.

Thanks.
Mar 17 '07 #1
Share this Question
Share on Google+
4 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
Greetings,
I need to brush up on my somewhat rusty Access skills. The problem I face is a very elementary one but for the life of me I cannot figure out how to solve it.

A form in my database needs to record the time a user adds a record and update this in the relevant table. I have created a textbox in the form which is bound to the associated field in the table. This textbox is hidden the locked, so the user will not be able to see or use it.

I am trying to display the time in this textbox when a command button is clicked. Since this textbox is bound to the relevant field in the table, that updates when the textbox's value changes. My textbox is "EntryTime", my command button "Save". Here's the code I currently have:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Save_Click()
  2. EntryTime.Text = Time
  3. End Sub
  4.  
This gives me the error "Runtime error 2185: You can't reference a property or method for a control unless the control has the focus". I have tried different variations on my code, but cannot get past this error.

I would greatly appreciate it if someone can shed some light on this.

Thanks.
You can't update a locked control.

Hide it and set enabled to false if you wish but don't lock it.

Mary
Mar 17 '07 #2

P: 3
You can't update a locked control.

Hide it and set enabled to false if you wish but don't lock it.

Mary
Thanks for the quick response. I tried unlocking the textbox but still get "Runtime error 2185: You can't reference a property or method for a control unless the control has the focus".

Thanks
Mar 17 '07 #3

P: 3
Thanks for the quick response. I tried unlocking the textbox but still get "Runtime error 2185: You can't reference a property or method for a control unless the control has the focus".

Thanks
Sorry, I forgot to add that I can change the value in textbox "EntryTime" with any of its own methods (LostFocus, etc.). Just can't seem to do it with any other control.
Mar 17 '07 #4

MMcCarthy
Expert Mod 10K+
P: 14,534
Try this ...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Save_Click()
  2.  
  3.    Me!EntryTime.SetFocus
  4.    Me!EntryTime.Value = Time
  5.  
  6. End Sub
Mary
Mar 17 '07 #5

Post your reply

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