Results 1 to 13 of 13

Thread: Auto date and user name in a textbox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    208

    Exclamation Auto date and user name in a textbox

    Hi, i have a textbox in my MS Access 97 form where different users can enter comments, however we can't track when and by whom. How can i add the date and the user name automatically everytime when the user click on the textbox and by keeping the previous comments in that textbox. Thanks

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Auto date and user name in a textbox

    you want to add fields to table to store date and user, or add to textbox text?

    in the click event
    VB Code:
    1. textbox.text = Now & " " & user & " " & textbox.text

    pete

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    208

    Re: Auto date and user name in a textbox

    The data from txtComments textbox is stored in my database (Comments) as a note field. So when i load the form, a user can add new comments below the previous comments.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Auto date and user name in a textbox

    VB Code:
    1. database(comments) = database(comments) & now & " " & user & vbnewline & txtcomments

    should do the trick

    pete

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    208

    Re: Auto date and user name in a textbox

    thanks its working. how can i make the text permanent that is the user can't erase the date and username.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Auto date and user name in a textbox

    use separate textboxs to display and add, don't save changes to the display one

    pete

  7. #7
    Member
    Join Date
    Oct 2005
    Posts
    34

    Re: Auto date and user name in a textbox

    use separate textboxs to display and add
    txtdisplaytext locked property: Yes
    VB code:
    txtaddtext_AfterUpdate
    txtdisplaytext=txtdisplaytext & now & " " & user & vbnewline & txtaddtext
    end sub
    then save txtdisplaytext to your database

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    208

    Re: Auto date and user name in a textbox

    i'm getting this error -
    " You can't reference a property or method for a control unless the control has the focus. I changed the txtAdd.setfocus i'm still getting the same error.

    VB Code:
    1. Private Sub txtAdd_AfterUpdate()
    2. txtDisplay.SetFocus
    3. txtDisplay.Text = txtDisplay.Text & vbNewLine & vbNewLine & Now() & " " & vbNewLine & CurrentUser() & vbNewLine & txtAdd.Text
    4. End Sub

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Auto date and user name in a textbox

    is txt display locked or otherwise disabled?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    208

    Re: Auto date and user name in a textbox

    the form is set up in a way that all the controls are locked therefore only viewing. If you need to modify then click the user has to click on the 'Edit' button to enable all the controls.

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Auto date and user name in a textbox

    is the txtdisplay still locked when you try to upate it, or are all the controls unlocked after edit is clicked?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    208

    Re: Auto date and user name in a textbox

    all the controls are unlocked after the edit button is clicked

  13. #13
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Auto date and user name in a textbox

    are these textboxs bound to the data?

    if so update the table/database the textbox should display
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width