If you
know how to set up the forms and command buttons. I just don't know how to get the computer name.
then you should know how to put in a single line of code. "Setting up" a command button has as its primary event, the Click event. Which is why cLFaVa informed you that, well, it should go in the Click event.
Study some of the FAQ on this forum.
For example, you do not need the result of computername to take up resources (and require the user to click OK on the message box). You could simply GET the computername and display it on a label on the form.
In other words, as the forms loads, it automatically gets the user's computername - with NO action required from the user, they do not have to click a command button. That name could be automatically written to a label (not a textbox) with your statement ""Your computer name is Office Computer BW56TH8900", or whatever.
Although I think I would state "You are logged in as (
login username, using the computer
computer name.
In that case, assuming a Lable named Label1 (and remember this is just a snippet of code, you may need much more stuff in here). If you do not know what the difference between a label anda textbox, look up Help. if you are just displaying text, use labels. The label.caption is what is displayed, and it can be changed whenever, and to whatever you want, on the fly. Just use Labelname.Caption = (the string you want it to be). Like this below.
Code:
UserForm_Initialize()
Label1.Caption = "You are logged in as " & ENVIRON("UserName") & _
", using the computer " & ENVIRON("ComputerName") & "."
This display the information, with no action needd by the user.
Gerry