Using the machine name in a form

E

Emy

Hello,

I would like a command (OnClick) to discriminate between computers names. In
other words, when I click on a button to select a form, a IF statement
should look at the machine name (=fOSUserName()) and if it´s Bob or Mary,
Then will move on to next form, otherwise, a message will alert that the
user is not allowed to open the selected form.

Can it be done?

TIA

Emy
 
M

Michel Walsh

Hi,



Forms have an Open even, with a Cancel argument you can set to true to
abort the opening:

Private Sub Form_Open(Cancel As Integer)
Cancel=NOT eval("fOSUserName() IN('bob', 'mary')"
End Sub


If the operation is so cancelled, a trappable error will occur. It is up to
you to code the proper error trapping in that case.

If you have multiple names, and eventually a variable list, someone can use
a DLookup on names in a table, rather than a IN list with constants written
in the code, as shown here:


Cancel = IsNull( DLookup("name", "Names", "name=fOSUserName() " ) )


If the DLookup does not find a name, it returns NULL, and Cancel is set to
true.


Hoping it may help,
Vanderghast, Access MVP
 
Top