Use Public Function UserName to populate Form field and bind it to table

May 26th, 2011 - 09:04 am ET by DIDS | Report spam
Hello,

I have a database where the user's enter their Windows ID into a text
box on a form. I would like to change it so that the field on the
form is automatically populated and the user's cannot change it. I
have a module with the below defined:

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

Public Function UserName() As String
Dim sName As String * 256
Dim cChars As Long
cChars = 256
If GetUserName(sName, cChars) Then
UserName = Left$(sName, cChars - 1)
End If
End Function


The text box currently has the Control Source set to OperatorRef#
which is in tblTempMeter. If I change the Control Source to
=UserName() it shows the Windows ID of the user but it does not put
that into the OperatorRef# field in tblTempMeter. How can I pass the
Windows ID from the text box to the OperatorRef# field in
tblTempMeter?

Thanks for any help you can provide,

DIDS
email Follow the discussionReplies 4 repliesReplies Make a reply

Replies

#1 Bob Quintal
May 26th, 2011 - 06:02 pm ET | Report spam
DIDS wrote in
news:
:

Hello,

I have a database where the user's enter their Windows ID into a
text box on a form. I would like to change it so that the field
on the form is automatically populated and the user's cannot
change it. I have a module with the below defined:

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

Public Function UserName() As String
Dim sName As String * 256
Dim cChars As Long
cChars = 256
If GetUserName(sName, cChars) Then
UserName = Left$(sName, cChars - 1)
End If
End Function


The text box currently has the Control Source set to OperatorRef#
which is in tblTempMeter. If I change the Control Source to
=UserName() it shows the Windows ID of the user but it does not
put that into the OperatorRef# field in tblTempMeter. How can I
pass the Windows ID from the text box to the OperatorRef# field in
tblTempMeter?

Thanks for any help you can provide,

DIDS




Leave the textbox control source set to OperatorRef#
set its .locked property to yes.
put the following code into the form's current event, changing the
value txtBoxName to the name of the textbox that contains
OperatorRef#

if me.newreord then
Me.txtBoxName = =UserName()
end if

Bob Q.
PA is y I've altered my address.

Similar topics