Autoupdate textbox after clicking on command button

sguan

Registered User.
Local time
Today, 13:30
Joined
Jul 7, 2011
Messages
10
I have a command button showing a username and also a textbox which is linked to a table with usernames on the same form

I want to autoupdate the textbox to show the username on the commandbutton when I click on the commandbutton.

Does anyone know the VBA codes for the on_click event procedure?

Thanks a lot!!
 
Welcome to the forum.

Is the user name on the Button fixed or is it being changed via code?
 
Last edited:
Something like...

Me.YourTextBox = Me.YourCommandButton.Caption

...in the On_Click event of the command button should work. But if the caption changes that could cause an issue.
 
The caption on the command button is fixed, but I forgot to mention that I have 10 command buttons with different suername and I want the username on that textbox to change accordingly.

Thanks so much for the replies!

I tried it and it works! :)))))

*******

One further question, so now when this textbox changes its username, I want to autoupdate a textbox showing username in another form.

Any ideas on how to perform this action? The code I have input so far is:

Private Sub Usertextbox_AfterUpdate()
Me.Requery
Varx = DLookup("[Username]", "User", "[Usertextbox]=[Forms]![Masterform]![User]")
Me.Form.[Usertextbox] = Varx

End Sub


but it doesnt seem to work......

Usertextbox is the textbox in form 1 with the commandbutton

User is the textbox in form 2 I want to autoupdate by changes in Usertextbox.

I hope I have explained it clear enough..

Your help is much appreciatedd!! Thanks a lot!
 
First up having 10 hard coded command buttons :eek: seems to be a rather inefficient way of doing things. What happens when you gain or loose a user?

Why not have a single command button and select the user from a combo box? This would be far easier to manage changes in your user base.

Now assuming that you second form is being opened from the one with all those buttons. You can pass information to it via the OpenArgs portion of the DoCmd.OpenForm, You can then collect/test the OpenArgs in the On Load event of the form being called. The sample here demonstrates how this works.
 

Users who are viewing this thread

Back
Top Bottom