record the name of person who creates the record

crosmill

Registered User.
Local time
Today, 14:10
Joined
Sep 20, 2001
Messages
285
I want to be make the user type in their name and then I want every record that is created under that name to be recorded with the record.

I think I'll need to declare a string variable, but I don't know how to set the column in the table to read this variable.

I'm also not sure about multiple users issues as I think the variable will be changed the the last login name.

I'd be very gratefull for any help.

Thanks
 
WITH USER-LEVEL SECURITY
Simply create a field in the table to record the user that created it. Create a text box on your form for that field and set its default value to CurrentUser(). You can set the text box's visible property to false so your users can't even see it.

WITHOUT USER-LEVEL SECURITY
This is tough, mainly for data integrity issues. What prevents a user from entering another name? However, to accomplish this, use an Autoexec macro to have the user type in their last name to a public variable on startup. Then, in the OnCurrent event of your form, type:

Code:
If Nz(Me.txtCreatedBy) = "" Then Me.txtCreatedBy = YourPublicVariableName

HTH

[This message has been edited by shacket (edited 10-22-2001).]
 
Thanks shacket, I can't get any of it to work though. I don't have a clue where to start implementing user level security and when I try to do it the other way you suggested I just can't make it work.

Is there any chace you could give me a more detailed solution.

TFYH
 
OK, without user-level security:

1. Create a field in your table called "CreatedBy"

2. Create a text box on your form called "txtCreatedBy" whose controlsource is the field "CreatedBy"

3. Create a macro called "Autoexec" with at least one line in it being:

RunCode (Put "Autoexec()" as the Function Name)

4. Create a module and insert the following in the module:

Code:
Public WhoCreated As String

Function Autoexec()
WhoCreated = InputBox("What is your name?","Enter Name")
End Function

5. In the OnCurrent event of your form, place the following code:

Code:
If Nz(Me.txtCreatedBy) = "" Then Me.txtCreatedBy = WhoCreated


That should do ya!

[This message has been edited by shacket (edited 10-23-2001).]
 
We use this code to grab the network user id then an vb/sql script to get their user details from a central(secure)database.

Private Declare Function api_GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Dim Buff As String
Dim BuffSize As Long
Dim result As Long
BuffSize = 256

Buff = Space$(BuffSize)
result = api_GetUserName(Buff, BuffSize)
GetUserN = Left$(Trim$(Buff), BuffSize - 1)
 
Thanks shacket that works dandy!

I don't understand the function part of the code though. I know autoexec runs on startup but I don't know why you put () on the end or what 'function' is.

When you create and input box is the bit before the = like creating a variable?

Thanks

danch, I haven't had a chace to look at your code yet but I'm not working from a secure db anyway.

Thanks again to you both, much appreiciated.

Chris



[This message has been edited by crosmill (edited 10-24-2001).]
 
Functions in VBA are a named set of procedures that can be "called" (run) from anywhere within your database. The code that I had you put in the module actually has two separate parts:

Public WhoCreated As String

This creates a public variable called "WhoCreated" as a string variable (a bunch of letters and numbers). A public variable retains its value even if you move from one procedure to the next. A private variable is only usable in the function or sub procedure in which it is called.

The next section:

Function Autoexec()
WhoCreated = InputBox("What is your name?","Enter Name")
End Function

The fucntion is named "Autoexec" (you could name it anything you want). The () at the end allow for variables to use in the function. For example, if you wanted a function to multiply the number sent to it by .08 (lets say...to figure 8% sales tax), you would write a function like this:

Function FigureTax(Amount As Long) As Long
FigureTax = Amount x .08
End Function

You would then call the function with:

FigureTax(432)

The function would then be equal to 8% of 432.

As far as the InputBox and variables, you wrote:

When you create and input box is the bit before the = like creating a variable?

The variable (WhoCreated) was established in the Public Declaration (as described above). What that statement does is open an input box with the assigned characteristics and assign the value of WhoCreated to what is entered.

HTH
 
Thats great thanks for all your help, I've learnt alot.

Thanks again.

Chris
 

Users who are viewing this thread

Back
Top Bottom