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.
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)