Populate form txtBox with current User & Date

C

Canuck

I'm in need of the code or syntax to autopopulate txtBox1 with th
current time & date and txtBox2 with the current User in an excel form
This is necessary to record who made changes to the data and when i
was done.

Any assistance would be greatly appreciated!

Canuc
 
C

Chip Pearson

Canuck,

Try something like the following:

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

Private Sub CommandButton1_Click()
Dim UN As String
Dim Res As Long
Dim L As Long
UN = String(255, " ")
L = Len(UN)
Res = GetUserName(UN, L)
UN = Left(UN, L - 1)
Me.TextBox1.Text = Format(Now, "hh:mm dd-mmm-yyyy")
Me.TextBox2.Text = UN
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

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

Top