Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

User Name

0 views
Skip to first unread message

Gary McCarthy

unread,
May 20, 2009, 6:52:01 PM5/20/09
to
I have a login form which captures the user name and places it into a global
string field called strUser.

What I need is for that value to be placed in a field called tbUser on each
record they enter without have to select there user name each time from, say,
a drop list.

My only idea was to set the value of tbUser with me.tbUser = strUser but I
get an error saying I can't update the object.

Any help is appreciated.

Thanks.

Dirk Goldgar

unread,
May 22, 2009, 3:49:34 PM5/22/09
to
"Gary McCarthy" <GaryMc...@discussions.microsoft.com> wrote in message
news:9581647C-641F-4418...@microsoft.com...

>I have a login form which captures the user name and places it into a
>global
> string field called strUser.

By "global string field", do you mean a global *variable*? I'm going to
assume that you do.

> What I need is for that value to be placed in a field called tbUser on
> each
> record they enter without have to select there user name each time from,
> say,
> a drop list.
>
> My only idea was to set the value of tbUser with me.tbUser = strUser but I
> get an error saying I can't update the object.

I'm not sure what you did to get that message, but here's one way to do what
you want.

Write a function that returns the value of your global string variable. For
example:

'----- start of code -----
Public Function fncUserName() As String

If Len(strUser) = 0 Then
' Something has cleared the user name!
' Make the user login again.
DoCmd.OpenForm "frmLogin", WindowMode:=acDialog
End If

fncUserName = strUser

End Function
'----- end of code -----

Put that function in a standard module, so that it is globally available.

Now, in every form where you update a table that has this tbUser field,
create an event procedure for the form's BeforeUpdate event, with code like
this:

'----- start of code -----
Private Sub Form_BeforeUpdate(Cancel As Integer)

Me.tbUser = fncUserName()

End Sub
'----- end of code -----

That should work. If it doesn't, you may have to add a text box bound to
tbUser to the form (you can make the text box hidden if you want), but I
think it should work even without any control bound to the field, so long as
tbUser is selected by the form's recordsource.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

0 new messages