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

D

DIDS

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
 
B

Bob Quintal

:
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
 
D

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.- Hide quoted text -

- Show quoted text -

Hi Bob,

I am getting "Compile Error: Method or data member not found". The VBA
editor is highlighting ".newreord" in the statement:

If Me.newreord Then
Me.OperRef# = UserName()
End If


The textbox Name on the Property sheet is "OperRef#" and the Control
Source has been changed back to "OperatorRef#". Any idea as to what is
wrong?


Thanks,

DIDS
 
D

DIDS

Hi Bob,

I discovered the issue. I changed the statement to:

Private Sub Form_Current()

Me.OperRef_.Value = UserName

End Sub

even though the textbox is called OperRef# it needed to be coded with
_ instead of #.

Thanks,

DIDS
 
R

rquintal

Hi Bob,

I am getting "Compile Error: Method or data member not found". The VBA
editor is highlighting ".newreord" in the statement:

If Me.newreord Then
        Me.OperRef# = UserName()
End If

The textbox Name on the Property sheet is "OperRef#" and the Control
Source has been changed back to "OperatorRef#". Any idea as to what is
wrong?

Thanks,

DIDS

Typographical error:
newreord should be newrecord
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top