Setting default value of textbox to Environ("username") not working (1 Viewer)

harmankardon

Registered User.
Local time
Today, 09:10
Joined
Aug 8, 2011
Messages
71
Hello all,

I am trying to set the default value of a textbox (for new records of course) to Environ("Username") by placing the following in the default value field in the textbox property sheet:

Code:
=Environ("Username")

When I go to a new record, my textbox is Null. I've tried with the equals sign and without the equals sign and both result in a Null value in the textbox.

I can type ?Environ("Username") in the immediate window and I get the expected result (my network username).

I can set the default value for the textbox in the On Current event and it works fine, just wondering why I can't use the default value field in the property sheet to do this. Other functions such as =Date() work fine in the default value field.

Any idea why this might not be working?

Thanks!
 

harmankardon

Registered User.
Local time
Today, 09:10
Joined
Aug 8, 2011
Messages
71
Well it seems I managed to figure this one out.

Putting =Environ("UserName") in the default value field for the textbox in the property sheet would not work no matter what I did so I made a standard code module with the following code:

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

Then in the default value field for the textbox I put =getWinUser() which works perfectly.

Could anyone shed any light as to why this worked?
 

dmyoungsal

Registered User.
Local time
Today, 05:10
Joined
May 1, 2016
Messages
112
Well it seems I managed to figure this one out.

Putting =Environ("UserName") in the default value field for the textbox in the property sheet would not work no matter what I did so I made a standard code module with the following code:

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

Then in the default value field for the textbox I put =getWinUser() which works perfectly.

Could anyone shed any light as to why this worked?

This thread is old, but it solved my problem! Thank you
 

Users who are viewing this thread

Top Bottom