Datestamp equivilent in Access 97
I need a way to add the current system date/time to a memo field in a form with a keystroke.
Even better, if the macro could include the name of the user logged into the system.
Can anyone help?
Software
I need a way to add the current system date/time to a memo field in a form with a keystroke.
Even better, if the macro could include the name of the user logged into the system.
Can anyone help?
by roc180
For current date/time use the DATE() function. To crab the current user in the system try Environ("S_User"). If you need more specific details let me know.
Good Luck
Neal Martinelli
by roc180
by sankulpune
Hello,
You can create a form based on the table or a query that is based on the table.
In the click event of the textbox (txbBox1) that corresponds to the memo field, you can paste the following code :
'***** Code start
Dim Date1 as string
Dim cUser as string
Date1 = CDate(Now)
CUser=Application.CurrentUser
txtBox1= "Todays date : " & Date1 & ", User Name : " & CUser
'***** Code Ends
The user will be the one logged while opening the database. If you want the network user (incase you don't need to login to use the database) you may need to use probably a WIN API function like GetUserName using declare. Or you need a function to read the value of the registry key :
HKEY_LOCAL_MACHINE\Network\Login\username
Your feedback will be highly appreciated.
With regards,
SanganakSakha
Simple & Effective Solutions To Small Problems, No QuickFixes.
by it_cowboy
there are 3 functions you can use
=Now() returns date and time in one field
=Date() returns date only
=Time() returns time only
Update the fields that need these values in them when you submit the memo (or whatever button you hit when you want the correct date and time used)
As for the current user try ...
Environ("USERNAME")
This will return the name of the user logged onto the network.
The environ function can also be called with a number, so if the above doesnt work (like the function returns a null or blank value), create a button on a form and enter this code for the click event...
Dim X as Integer
For X = 1 to 999
MsgBox Environ(X)
Next
The message box will display something like
"USERNAME=SmithJ". Keep answering the message until you find the variable you want.
Whatever the word before the = sign is the name of the environmental variable. Try this anyway, you may find some other handy variables to shortcut a few things.
If you have security set up in access and you want to determine that user, just use
'CurrentUser', this is an Access generated variable.
by it_cowboy
if you really want to get Access to do anything neat, get away from macro's. They are handy for some things but there comes a time when macro's just dont cut it. For this you will need a macro to initiate on the key press, but the rest should be done with a function.
however, create a macro called "autokeys". Access looks for this when keys are pressed. In the macro, make sure you have the macro name column visible and enter in the name of a key you want to use to trigger the macro. If you want to use F4, enter in {F4} in the macro name field. The rest of the macro should be ok (i think).
PS: I have an Access book at home in which one of the chapters is called 'macros are for weenies, code is cool'. lol - i think that says it all.
I hope one of the folks who answered will see this. Sorry for the delay, I got pulled away to another project, but now I need this concept again. I'm currently trying to get this to work in a date field and still having trouble. I thought at first it was because I had applied an input mask. But I deleted it for the field I'm testing in the table, query and form.
I created a macro named ^d. I tried it both as a macro group name with this as the only macro, and as the macro name inside anexsisting group. The macro action was SetValue. The item is Screen].
[ActiveControl] and the Expression is Date()
I tried activating it with a button on the form, to see if the problem was the macro, or the activation of it. When I use the button, I get an error message that says "You can't assign a value to this object. The object may be a control on a read-only form. The object may be on a form that is open in design view. The value may be too large for this field."
None of these things are true. I can type today's date in the field and it is accepted.
This discussion is closed to new replies.
Sort by Trending