Insert username into text box

  • Follow


I am using the fOSUserName functionality in my DB. I would like to use it to 
dynamically preface comments a user types into a text box.

Scenario...user opens a ticket form, starts typing a comment in the text 
box, and Access automatically inserts their username in front of their 
comments (in bold typeface if possible) followed by a couple spaces, or a 
space dash space.

Any ideas? Thanks!
0
Reply Utf 1/24/2008 5:23:04 PM

Paul,
   Use the AfterUpdate event of your text control (ex. control name = 
[Comments])
       Me.Comments = CurrentUser & " - " & [Comments]
-- 
    hth
    Al Campagna
    Microsoft Access MVP
    http://home.comcast.net/~cccsolutions/index.html

    "Find a job that you love... and you'll never work a day in your life."

"Paul" <Paul@discussions.microsoft.com> wrote in message 
news:13E70263-D749-4C69-92D9-040F98E3938D@microsoft.com...
>I am using the fOSUserName functionality in my DB. I would like to use it 
>to
> dynamically preface comments a user types into a text box.
>
> Scenario...user opens a ticket form, starts typing a comment in the text
> box, and Access automatically inserts their username in front of their
> comments (in bold typeface if possible) followed by a couple spaces, or a
> space dash space.
>
> Any ideas? Thanks! 


0
Reply Al 1/24/2008 5:37:10 PM


Paul,

I would recommend against this, since it violates the 1st Normal form (more 
than one piece of information in a field).  Instead, I recommend you add a 
UserID field to the table, and update it before a record is written.

But it sounds like you want to use this textbox as a running summation of 
comments made by multiple people about a particular ticket.  If that is so, 
then what you really need is a separate table that contains the fields for a 
foreign key (TicketID), UserID, Comment, and dtEntered (date/time field).

Then, you can create a subform that displays all of these fields.  You can 
set the txt_UserID controls default value to "=fOSUserName()" so that it 
automatically gets entered when you create a new record.

HTH
Dale

rather than using a single textbox, you create a  
-- 
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.



"Paul" wrote:

> I am using the fOSUserName functionality in my DB. I would like to use it to 
> dynamically preface comments a user types into a text box.
> 
> Scenario...user opens a ticket form, starts typing a comment in the text 
> box, and Access automatically inserts their username in front of their 
> comments (in bold typeface if possible) followed by a couple spaces, or a 
> space dash space.
> 
> Any ideas? Thanks!
0
Reply Utf 1/24/2008 6:44:04 PM

These are both good suggestions, but might I add mine.  If you don't have any 
user setting setup or login, etc.

On the After Update of any field or record:

me.[textbox, field, note, whatever you decide to update] = environ("USERNAME")

....this will update the field with the users environ settings, basically the 
same way that it would update a comment in a note in excel.  

"Paul" wrote:

> I am using the fOSUserName functionality in my DB. I would like to use it to 
> dynamically preface comments a user types into a text box.
> 
> Scenario...user opens a ticket form, starts typing a comment in the text 
> box, and Access automatically inserts their username in front of their 
> comments (in bold typeface if possible) followed by a couple spaces, or a 
> space dash space.
> 
> Any ideas? Thanks!
0
Reply Utf 1/24/2008 6:51:03 PM

I always cringe when I see someone recommending using the Environ function 
to get user name. It's trivial to reset the value of the environment 
variable for the duration of the Access session.

Paul's mentioned fOSUserName, which is presumably the code from 
http://www.mvps.org/access/api/api0008.htm at "The Access Web" that 
demonstrates the GetUserName API that's far, far more reliable than Environ.

-- 
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"meyerryang" <meyerryang@discussions.microsoft.com> wrote in message 
news:F24A5941-113A-4214-AB26-FD041DFE4133@microsoft.com...
> These are both good suggestions, but might I add mine.  If you don't have 
> any
> user setting setup or login, etc.
>
> On the After Update of any field or record:
>
> me.[textbox, field, note, whatever you decide to update] = 
> environ("USERNAME")
>
> ...this will update the field with the users environ settings, basically 
> the
> same way that it would update a comment in a note in excel.
>
> "Paul" wrote:
>
>> I am using the fOSUserName functionality in my DB. I would like to use it 
>> to
>> dynamically preface comments a user types into a text box.
>>
>> Scenario...user opens a ticket form, starts typing a comment in the text
>> box, and Access automatically inserts their username in front of their
>> comments (in bold typeface if possible) followed by a couple spaces, or a
>> space dash space.
>>
>> Any ideas? Thanks! 


0
Reply Douglas 1/24/2008 7:37:09 PM

Since I'm just looking to add a simple identifier of the person who added the 
specific update, I decided to use the option Al provided in the After Update, 
but I substituted 'CurrentUser' with fOSUserName():

Me.Comment = fOSUserName() & " - " & [Comment]

This works great for what I'm wanting to do.

Two more items...

1. I would really like to be able to bold the username and not the rest of 
the text in the text box but I don't believe this can be done with Access '03 
in it's maiden form.

2. I wouldn't mind being able to tie the fOSUserName value back to my 
'Contacts' table which has a field for the network logon id...and then return 
back the 'Name' field from that table (Contacts) and show it instead of their 
network logon id, aka the fOSUserName.

Suggestions?



"Paul" wrote:

> I am using the fOSUserName functionality in my DB. I would like to use it to 
> dynamically preface comments a user types into a text box.
> 
> Scenario...user opens a ticket form, starts typing a comment in the text 
> box, and Access automatically inserts their username in front of their 
> comments (in bold typeface if possible) followed by a couple spaces, or a 
> space dash space.
> 
> Any ideas? Thanks!
0
Reply Utf 1/24/2008 8:02:01 PM

"Paul" <Paul@discussions.microsoft.com> wrote in message 
news:B0B0FC37-FA0F-4576-878D-BF21D14DFE92@microsoft.com...
> Since I'm just looking to add a simple identifier of the person who added 
> the
> specific update, I decided to use the option Al provided in the After 
> Update,
> but I substituted 'CurrentUser' with fOSUserName():
>
> Me.Comment = fOSUserName() & " - " & [Comment]
>
> This works great for what I'm wanting to do.
>
> Two more items...
>
> 1. I would really like to be able to bold the username and not the rest of
> the text in the text box but I don't believe this can be done with Access 
> '03
> in it's maiden form.

You're correct that there's no way to bold only part of the text in 
"vanilla" Access 2003: you'd have to use an RTF control, and I think you'd 
find that far more effort than it's worth.

> 2. I wouldn't mind being able to tie the fOSUserName value back to my
> 'Contacts' table which has a field for the network logon id...and then 
> return
> back the 'Name' field from that table (Contacts) and show it instead of 
> their
> network logon id, aka the fOSUserName.

Me.Comment = DLookup("[Name]", "[Contacts]", "LogonId ='" & fOSUserName() & 
"'") & " - " & [Comment]

(or whatever the field name is rather than LogonId). Note that's ' " before 
the ampersand, and " ' " after it.

Note that Name isn't actually a good choice for a field name: it's a 
reserved word, and you shouldn't use reserved words for your own purposes. 
For a good discussion of what names to avoid, see what Allen Browne has at 
http://www.allenbrowne.com/AppIssueBadWord.html

-- 
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



0
Reply Douglas 1/24/2008 8:12:42 PM

Thanks, that worked very well...one last question...how would your line of 
code differ if I wanted to include 2 fields so I had the first and last name?

I tried playing around with it, but was unable to make it work. I take that 
back, I could get it to pull both back, but I couldn't get it to put a space 
between the First and Last name so I got 'FirstLast -' instead of 'First Last 
- '.

"Douglas J. Steele" wrote:

> "Paul" <Paul@discussions.microsoft.com> wrote in message 
> news:B0B0FC37-FA0F-4576-878D-BF21D14DFE92@microsoft.com...
> > Since I'm just looking to add a simple identifier of the person who added 
> > the
> > specific update, I decided to use the option Al provided in the After 
> > Update,
> > but I substituted 'CurrentUser' with fOSUserName():
> >
> > Me.Comment = fOSUserName() & " - " & [Comment]
> >
> > This works great for what I'm wanting to do.
> >
> > Two more items...
> >
> > 1. I would really like to be able to bold the username and not the rest of
> > the text in the text box but I don't believe this can be done with Access 
> > '03
> > in it's maiden form.
> 
> You're correct that there's no way to bold only part of the text in 
> "vanilla" Access 2003: you'd have to use an RTF control, and I think you'd 
> find that far more effort than it's worth.
> 
> > 2. I wouldn't mind being able to tie the fOSUserName value back to my
> > 'Contacts' table which has a field for the network logon id...and then 
> > return
> > back the 'Name' field from that table (Contacts) and show it instead of 
> > their
> > network logon id, aka the fOSUserName.
> 
> Me.Comment = DLookup("[Name]", "[Contacts]", "LogonId ='" & fOSUserName() & 
> "'") & " - " & [Comment]
> 
> (or whatever the field name is rather than LogonId). Note that's ' " before 
> the ampersand, and " ' " after it.
> 
> Note that Name isn't actually a good choice for a field name: it's a 
> reserved word, and you shouldn't use reserved words for your own purposes. 
> For a good discussion of what names to avoid, see what Allen Browne has at 
> http://www.allenbrowne.com/AppIssueBadWord.html
> 
> -- 
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
> 
> 
> 
> 
0
Reply Utf 1/24/2008 9:36:47 PM

You can actually cheat, and have DLookup return two fields at once:

Me.Comment = DLookup("[FirstName] & ' ' & [LastName]", "[Contacts]", 
"LogonId ='" & fOSUserName() & "'") & " - " & [Comment]

Note that's a pair of single quotes, separated by a space, between the 
names.

-- 
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Paul" <Paul@discussions.microsoft.com> wrote in message 
news:D450F314-108E-41D1-B838-C8763DF4BC47@microsoft.com...
> Thanks, that worked very well...one last question...how would your line of
> code differ if I wanted to include 2 fields so I had the first and last 
> name?
>
> I tried playing around with it, but was unable to make it work. I take 
> that
> back, I could get it to pull both back, but I couldn't get it to put a 
> space
> between the First and Last name so I got 'FirstLast -' instead of 'First 
> Last
> - '.
>
> "Douglas J. Steele" wrote:
>
>> "Paul" <Paul@discussions.microsoft.com> wrote in message
>> news:B0B0FC37-FA0F-4576-878D-BF21D14DFE92@microsoft.com...
>> > Since I'm just looking to add a simple identifier of the person who 
>> > added
>> > the
>> > specific update, I decided to use the option Al provided in the After
>> > Update,
>> > but I substituted 'CurrentUser' with fOSUserName():
>> >
>> > Me.Comment = fOSUserName() & " - " & [Comment]
>> >
>> > This works great for what I'm wanting to do.
>> >
>> > Two more items...
>> >
>> > 1. I would really like to be able to bold the username and not the rest 
>> > of
>> > the text in the text box but I don't believe this can be done with 
>> > Access
>> > '03
>> > in it's maiden form.
>>
>> You're correct that there's no way to bold only part of the text in
>> "vanilla" Access 2003: you'd have to use an RTF control, and I think 
>> you'd
>> find that far more effort than it's worth.
>>
>> > 2. I wouldn't mind being able to tie the fOSUserName value back to my
>> > 'Contacts' table which has a field for the network logon id...and then
>> > return
>> > back the 'Name' field from that table (Contacts) and show it instead of
>> > their
>> > network logon id, aka the fOSUserName.
>>
>> Me.Comment = DLookup("[Name]", "[Contacts]", "LogonId ='" & fOSUserName() 
>> &
>> "'") & " - " & [Comment]
>>
>> (or whatever the field name is rather than LogonId). Note that's ' " 
>> before
>> the ampersand, and " ' " after it.
>>
>> Note that Name isn't actually a good choice for a field name: it's a
>> reserved word, and you shouldn't use reserved words for your own 
>> purposes.
>> For a good discussion of what names to avoid, see what Allen Browne has 
>> at
>> http://www.allenbrowne.com/AppIssueBadWord.html
>>
>> -- 
>> Doug Steele, Microsoft Access MVP
>> http://I.Am/DougSteele
>> (no e-mails, please!)
>>
>>
>>
>> 


0
Reply Douglas 1/24/2008 10:16:02 PM

Works like a charm, thanks Doug! I was making the mistake of using double 
quotes instead of single quotes!

"Douglas J. Steele" wrote:

> You can actually cheat, and have DLookup return two fields at once:
> 
> Me.Comment = DLookup("[FirstName] & ' ' & [LastName]", "[Contacts]", 
> "LogonId ='" & fOSUserName() & "'") & " - " & [Comment]
> 
> Note that's a pair of single quotes, separated by a space, between the 
> names.
> 
> -- 
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no private e-mails, please)
> 
> 
> "Paul" <Paul@discussions.microsoft.com> wrote in message 
> news:D450F314-108E-41D1-B838-C8763DF4BC47@microsoft.com...
> > Thanks, that worked very well...one last question...how would your line of
> > code differ if I wanted to include 2 fields so I had the first and last 
> > name?
> >
> > I tried playing around with it, but was unable to make it work. I take 
> > that
> > back, I could get it to pull both back, but I couldn't get it to put a 
> > space
> > between the First and Last name so I got 'FirstLast -' instead of 'First 
> > Last
> > - '.
> >
> > "Douglas J. Steele" wrote:
> >
> >> "Paul" <Paul@discussions.microsoft.com> wrote in message
> >> news:B0B0FC37-FA0F-4576-878D-BF21D14DFE92@microsoft.com...
> >> > Since I'm just looking to add a simple identifier of the person who 
> >> > added
> >> > the
> >> > specific update, I decided to use the option Al provided in the After
> >> > Update,
> >> > but I substituted 'CurrentUser' with fOSUserName():
> >> >
> >> > Me.Comment = fOSUserName() & " - " & [Comment]
> >> >
> >> > This works great for what I'm wanting to do.
> >> >
> >> > Two more items...
> >> >
> >> > 1. I would really like to be able to bold the username and not the rest 
> >> > of
> >> > the text in the text box but I don't believe this can be done with 
> >> > Access
> >> > '03
> >> > in it's maiden form.
> >>
> >> You're correct that there's no way to bold only part of the text in
> >> "vanilla" Access 2003: you'd have to use an RTF control, and I think 
> >> you'd
> >> find that far more effort than it's worth.
> >>
> >> > 2. I wouldn't mind being able to tie the fOSUserName value back to my
> >> > 'Contacts' table which has a field for the network logon id...and then
> >> > return
> >> > back the 'Name' field from that table (Contacts) and show it instead of
> >> > their
> >> > network logon id, aka the fOSUserName.
> >>
> >> Me.Comment = DLookup("[Name]", "[Contacts]", "LogonId ='" & fOSUserName() 
> >> &
> >> "'") & " - " & [Comment]
> >>
> >> (or whatever the field name is rather than LogonId). Note that's ' " 
> >> before
> >> the ampersand, and " ' " after it.
> >>
> >> Note that Name isn't actually a good choice for a field name: it's a
> >> reserved word, and you shouldn't use reserved words for your own 
> >> purposes.
> >> For a good discussion of what names to avoid, see what Allen Browne has 
> >> at
> >> http://www.allenbrowne.com/AppIssueBadWord.html
> >>
> >> -- 
> >> Doug Steele, Microsoft Access MVP
> >> http://I.Am/DougSteele
> >> (no e-mails, please!)
> >>
> >>
> >>
> >> 
> 
> 
> 
0
Reply Utf 1/25/2008 1:04:00 PM

9 Replies
144 Views

(page loaded in 1.037 seconds)

Similiar Articles:
















7/17/2012 11:08:55 AM


Reply: