Text box changes

Factor21

Registered User.
Local time
Today, 20:23
Joined
Aug 27, 2014
Messages
17
I have a text box that pulls the Windows User Id into a form, I need this to set once a new record is created and not to change when someone else views the record.

The user id is pulled via a module and this module is referenced in the default value field on the Data tab of the properties sheet.

Code:
Public Function getWinUser() As String
getWinUser = Environ("UserName")
End Function


Thanks in advance
 
First, you may be better to use fOSUserName() - google it! - for a more robust user name formula. Environ() can be spoofed.

Now, what you want is for your form to check the NewRecord property.

In your form load event, try something like:

Code:
If Me.NewRecord Then
    Me.txtYourTextBox.Enabled = True
Else
    Me.txtYourTextBox.Enabled = False
End If

or, more succinctly:

Code:
Me.txtYourTextBox.Enabled = Me.NewRecord
 
Have you considered using If IsNull(Me.name of txt box of user ) prior to the call statement in the module that calls the get window user ? that way it will not over write the user name txt box . Just a user not a profession
Hope this of some use to you
Regards YPMA
 
I found the code below and have associated it with the text box, how do I get the user name to populate in the table, apologies I did say I was new.....

Code:
'******************** Code Start **************************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
    strUserName = String$(254, 0)
    lngLen = 255
    lngX = apiGetUserName(strUserName, lngLen)
    If (lngX > 0) Then
        fOSUserName = Left$(strUserName, lngLen - 1)
    Else
        fOSUserName = vbNullString
    End If
End Function
'******************** Code End **************************
 
I have now got the "fOSUserName" working instead of the "GetWinUser".

With regard to the code for checking the NewRecord, do I need to create a standard module for this and refer the ON LOAD to the module.

Apologies if really easy, I'm really new to programming with Access.

Thanks in advance
 
You can do it in the form's module. That's where the Form_Load event is.
 

Users who are viewing this thread

Back
Top Bottom