none
Update DB table with Environ("UserName") RRS feed

  • Question

  • Hi,

    this code shows username in a form text box:

    Code:
    Private Sub txtUserName_Change()
      txtUserName.Text = Environ("UserName")
    End Sub
    what I want is, on update click, it adds the username to the data table and shows in another bound text box.

    Sincerly
    iboumiza
    Tuesday, July 26, 2011 5:16 PM

Answers

  • Hi iboumiza

    iboumiza wrote:

    this code shows username in a form text box:

    Private Sub txtUserName_Change()
     txtUserName.Text = Environ("UserName")
    End Sub

    what I want is, on update click, it adds the username to the data
    <http://www.vbforums.com/showthread.php?p=4044721#> table and shows in
    another bound text box.

    writing data to the table should be done in the form_beforeupdate event, else you will change the recordsource of your form with this update and would have to requery it.

    if you have an "update" button then just run following code in the onClick event:

    Me.Dirty=False

    Then the form_beforeupdate event should be fired (if something has changed in the form and the form is bound).
    In there you can use following code:
    Me!YourUserNameField = Environ("UserName")

    On the form_current event you can display the content of this field in another textbox:
    Me!YourOtherTextBox = Me!YourUserNameField

    HTH
    Henry

    • Marked as answer by iboumiza Wednesday, July 27, 2011 6:22 PM
    Wednesday, July 27, 2011 5:52 AM

All replies

  • Hi iboumiza

    iboumiza wrote:

    this code shows username in a form text box:

    Private Sub txtUserName_Change()
     txtUserName.Text = Environ("UserName")
    End Sub

    what I want is, on update click, it adds the username to the data
    <http://www.vbforums.com/showthread.php?p=4044721#> table and shows in
    another bound text box.

    writing data to the table should be done in the form_beforeupdate event, else you will change the recordsource of your form with this update and would have to requery it.

    if you have an "update" button then just run following code in the onClick event:

    Me.Dirty=False

    Then the form_beforeupdate event should be fired (if something has changed in the form and the form is bound).
    In there you can use following code:
    Me!YourUserNameField = Environ("UserName")

    On the form_current event you can display the content of this field in another textbox:
    Me!YourOtherTextBox = Me!YourUserNameField

    HTH
    Henry

    • Marked as answer by iboumiza Wednesday, July 27, 2011 6:22 PM
    Wednesday, July 27, 2011 5:52 AM
  • thank you!

    It's working

    Wednesday, July 27, 2011 6:46 PM