Assign value to textbox

johndoomed

VBA idiot
Local time
Today, 12:27
Joined
Nov 4, 2004
Messages
174
This is a real simple question, I think. But I cant get it to work.

I want to change the value in a textbox. The form (and box) is connected to a table. This is my code:
PHP:
    user = Environ("USERNAME")
    
    If user = "jel" Then
        [Person ID] = 1
    ElseIf user = "nho" Then
        MsgBox ("Testing NHO")
    Else
        MsgBox (user)
    End If

As you can see, I want to change the value of the textbox [Person ID] based on which user (Windows) is loged in.

What do i get wrong?
 
I'm a little confused about what your trying to say. Do you want a text box to be updated or have a message box?

Maybe you could set up an unassigned text box and use a case statement based upon your criteria.

Code:
Sub test()
    User = Environ("username")
    Select Case User
      Case "jel"
        txtUserID = 1
      Case "nho"
        txtUserID = 2
      Case Else
        txtUserID = 3
    End Select
End Sub 'test
 
I've tried with Me.[Person ID]=1, but that dont work.

However, the code works on a unbound box.. (Me.[Unbound]=1)

I can change [Person ID] manually, so the form seems alright.

I dont understand this...
 
When the form starts. Onstart? (Not sure what it's called in English)
 
I'm not sure what it is called in your version but in English we have an OnOpen event and then an OnLoad event. OnOpen is too early in the process to refer to controls on the form so you need to use the OnLoad event. Try putting your code under a temporary command button to test it until you get everything working.
 

Users who are viewing this thread

Back
Top Bottom