Append comments field with user name (1 Viewer)

William Demuth

Registered User.
Local time
Today, 03:57
Joined
Feb 16, 2011
Messages
35
Howdy

I need to save a user's machine name when they comment on a record.

I have a form that has a comments field, and a separate area that shows the historical entries from comments.

I also have an invisible field populated by "=fOSMachineName()" that shows the users machine name. Getting this running was tough on my 64 bit machine, but it now works!):banghead:

I wish to have the machine name included in the comments field every time the "Save Record and Close" button (which runs a macro) is clicked.

Right now, when someone adds comments, it shows a date and time stamp (which I still want to keep) but I want to also capture the machine name at the same time.

Can anyone point me in the right direction?
 

CazB

Registered User.
Local time
Today, 08:57
Joined
Jul 17, 2013
Messages
309
is it going in the same field as the comments, or in a separate one?
 

William Demuth

Registered User.
Local time
Today, 03:57
Joined
Feb 16, 2011
Messages
35
Either approach is acceptable.

Same is probably the easier path so lets try that one, and I can extrapolate out the other after I have another Mountain Dew!
 

pr2-eugin

Super Moderator
Local time
Today, 08:57
Joined
Nov 30, 2011
Messages
8,494
Howdy William Demuth, Well how is your table structured? Does it have two separate fields to record this piece of information? Is the table the user interacts related to the historic information table?

EDIT: Way too slow there.. ;) Carry on Caz..
 

CazB

Registered User.
Local time
Today, 08:57
Joined
Jul 17, 2013
Messages
309
Personally, I'd go with a separate field, but that's my choice (easier to filter comments made by the same user, etc)

Anyway:
I have something similar on mine.... and I just put the following code on my Save button... but you COULD put it on another event if it works better for you. (I have 2 separate fields in my table - LastUpdateBy which stores the username, and LastUpdateDate which stores the date and time)

Code:
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
 
        Me.LastUpdateBy = CurrentUser()
        Me.LastUpdateDate = Now()
        DoCmd.RunCommand acCmdSaveRecord
 
Exit_cmdSave_Click:
    Exit Sub
Err_cmdSave_Click:
    MsgBox Err & "  - " & Err.Description
    Resume Exit_cmdSave_Click
End Sub

You could amend this using your own function:

Me.LastUpdateBy = fOSMachineName()

OR if you're stuck with one field then it gets slightly more complicated:

I personally would change the text control where the user puts their comments to an unbound control, and then when they save the record, add in something like

me.yourCommentsfield = me.yourunboundcontrolname & " : " & fOSMachineName()

[Edit - please jump in if you have any other ideas, Paul!]
 

pr2-eugin

Super Moderator
Local time
Today, 08:57
Joined
Nov 30, 2011
Messages
8,494
I would go for separate fields as Caz has suggested.. All the more reasons for which she has mentioned.. Search made easy and less messy..

However I would add one variation, Create a new table to record historic log.. That is of course if you are looking for something like that.. As you know every time someone access the Record, the information LastUpdated and LastModified changes.. If you want an historic logger, then you might want to look into AuditTrail..
 

CazB

Registered User.
Local time
Today, 08:57
Joined
Jul 17, 2013
Messages
309
I have AuditTrail on mine as well, lol..... belt and braces ;)
 

William Demuth

Registered User.
Local time
Today, 03:57
Joined
Feb 16, 2011
Messages
35
Way cool!

Having only a 7th grade education and ending up a programmer I am ALWAYS amazed when I learn something new!!

One last issue before I order you a gold plated pocket protector.

I have what I need, but now I have TWO save and close buttons. (I know, seems silly right!)

The original runs a macro with several steps.

Any clue how to combine them, I tried the original with a run code line added, but it wont find cmdSave_Click(). Perhaps because it is embedded in the other button?

Any other approaches you might offer
 

pr2-eugin

Super Moderator
Local time
Today, 08:57
Joined
Nov 30, 2011
Messages
8,494
Simply convert it to VBA.. It is so much easier..
 

William Demuth

Registered User.
Local time
Today, 03:57
Joined
Feb 16, 2011
Messages
35
Look at me!

I got it beat, Thank you both!

Nothing further needed, just curious why you have a last date changed field, when the last user field would have a date and time stamp?

In any event BRAVO gentleman, you both have a slot waiting in my Zombie Apocalypse bunker. :D
 

William Demuth

Registered User.
Local time
Today, 03:57
Joined
Feb 16, 2011
Messages
35
Where ya been all my life?

Normally if I even MENTION this stuff to a woman they run away get that glassy eyed look.

Double the Kudos for you, we need more like you
 

Users who are viewing this thread

Top Bottom