Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

API Issue

Status
Not open for further replies.

newbieone

Technical User
Jan 3, 2006
50
US
I have a database that is supposed to attach the Network user name to the record using an API script when the record is new. However, it does not seem to be working. can anyone give me some help with this?
 
How about posting the script to give us a place to start.



Andy Baldwin

"Testing is the most overlooked programming language on the books!
 
Here's the code.

Public Function StampRecord(frm As Form, Optional bHasInactive As Boolean = False) As Boolean
On Error GoTo Err_StampRecord
'Purpose: Stamp the user and date/time into the record.
'Return: True if successful.
'Argument: frm = the bound form to be stamped.
' bHasInactive= True if the form has Inactive fields.
'Assumes: Fields named EnteredOn, EnteredBy, UpdatedOn, and UpdatedBy.
'Usage: In Form_BeforeUpdate:
' Call StampRecord(Me, True)
Dim strForm As String
Dim strUser As String

strForm = frm.Contactsfrm 'For error handler.
strUser = NetworkUserName()

If frm.NewRecord Then
frm!EnteredOn = Now()
frm!EnteredBy = strUser
Else
frm!UpdatedOn = Now()
frm!UpdatedBy = strUser
End If
Exit_StampRecord:
Exit Function

Err_StampRecord:
Call LogError(Err.Number, Err.Description, conMod & "StampRecord()", "Form = " & strForm)
Resume Exit_StampRecord
End Function
 
Have you tried the Environ("UserName") function?
 
Can I use this function to add the username to a table? or does it have to be associated with an unbound text box?
 
hello,

Try replacing this line
strUser = NetworkUserName()

with

strUser = Environ("UserName")

Then let the rest of your code continue.

Andy Baldwin

"Testing is the most overlooked programming language on the books!
 
ok tried replacing str=NetworkUserName() with strUser=environ("UserName") and it didn't work. It acts like the code is either being ignored or is not being triggered.
 
Where and how is StampRecord called ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I had it on the BeforeUpdate() sub for the form. since that was not working I tried moving to the AfterUpdate still not working

Private Sub Form_AfterUpdate(Cancel as Integer)
Call StampRecord (Me, True)
end sub

 
Getting an error

error 2465 application-defined or Object-defined error when I close the form. does this have something to do with the Call Stamprecord not being triggered?
 
Private Sub Form_AfterUpdate(Cancel as Integer)
The form's AfterUpdate event procedure has NO argument at all ...
 
Sorry, YOU lost me.
The code you posted 7 Jul 06 8:33 is a NON SENSE in a form's class module.
 
Ok so How should it look? I thought that if you called a public function an argument was not needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top