Home Forums Microsoft Access Microsoft Access Update Field to current logged in user ID with new record command button RE: Update Field to current logged in user ID with new record command button

  • You haven't indicated that the line of code:

    Me.txtUserID = Environ("UserName")

    is executing. You will have to figure that out.

    I would take out the line:

    On Error Resume Next

    Also, set VB Editor to "Break on all Errors"

    Try this code instead of what you have:

    Private Sub cmdNewRecord_Click()

    On Error GoTo cmdNewRecord_Click_Err

    If Not .NewRecord Then DoCmd.RunCommand acCmdRecordsGoToNew

    Me.txtUserID = Environ("UserID")

    cmdNewRecord_Click_Exit:

    Exit Sub

    cmdNewRecord_Click_Err:

    MsgBox Err.Number & " - " & Err.Description

    Resume cmdNewRecord_Click_Exit

    End Sub