Default User ID and Date

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using the cade below to enter the userID of the person up-dating my
database.
I then use the form's BeforeUpdate event procedure to set the value of the
UserID field when a the record is added.
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.UserID) Then
Me!UserID = fOSUserName
End If
End Sub

This works well when a record is entered manually. However when I use an
append query to add records, one or more the UserID field does not up-date.
I also use the default value property Date() to enter the date the record
was entered, again this works when adding a manual entry but this does not
up-date when using the append query.

I would appreciate any help with these two issues.

Regards
Nick

'******************** Code Start **************************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If ( lngX > 0 ) Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = vbNullString
End If
End Function
'******************** Code End **************************
 
You can use the function call in your Append query.

In query design, just type:
fOSUserName()
into a fresh column in the Field row, and choose the UserID field in the
Append To row.

Similarly for the date field.
 
Fantastic
Thanks very much Allen

Regards
Nick


Allen Browne said:
You can use the function call in your Append query.

In query design, just type:
fOSUserName()
into a fresh column in the Field row, and choose the UserID field in the
Append To row.

Similarly for the date field.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top