UserName Q:

A

Ana

Hi,
I would like to block the following control buttoms if the user is not me on
a PC.
However, it's not working.
What's wrong with the following expression?
TIA
Win xppro - AccessXP

Private Sub Form_Open(Cancel As Integer)
DoCmd.Maximize
If "UserName" = "roma" Then
Me.Command42.Enabled = True
Me.Command43.Enabled = True
Me.Command44.Enabled = True
End If
End Sub
 
A

Andi Mayer

Hi,
I would like to block the following control buttoms if the user is not me on
a PC.
However, it's not working.
What's wrong with the following expression?
TIA
Win xppro - AccessXP

Private Sub Form_Open(Cancel As Integer)
DoCmd.Maximize
If "UserName" = "roma" Then
Me.Command42.Enabled = True
Me.Command43.Enabled = True
Me.Command44.Enabled = True
End If
End Sub
are you sure this buttons are enabled=false?

Private Sub Form_Open(Cancel As Integer)
DoCmd.Maximize
dim isEnabled as boolean
If "UserName" = "roma" Then isEnabled=true
Me.Command42.Enabled = isEnabled
Me.Command43.Enabled = isEnabled
Me.Command44.Enabled = isEnabled

End Sub
 
W

Wayne Morgan

First, you only set them to Enabled = True, if the default setting for these
buttons is Enabled = False, this should work since you wouldn't be able to
change users without closing the database.

Next, you have
If "UserName" = "roma" Then

You are checking the text "UserName" against the text "roma", they are NOT
equal. If UserName is a variable, remove the quotes from around it. Whether
or not that will work for you depends on how you are assigning the user's
name to UserName. You haven't shown us that. Also, UserName is a reserved
word and shouldn't be used as a variable name.

Which user name are you after, the Access logon name or the computer's logon
name?
 
A

Ana

Thank you.
I'm after the PC logon name.

Wayne Morgan said:
First, you only set them to Enabled = True, if the default setting for
these buttons is Enabled = False, this should work since you wouldn't be
able to change users without closing the database.

Next, you have

You are checking the text "UserName" against the text "roma", they are NOT
equal. If UserName is a variable, remove the quotes from around it.
Whether or not that will work for you depends on how you are assigning the
user's name to UserName. You haven't shown us that. Also, UserName is a
reserved word and shouldn't be used as a variable name.

Which user name are you after, the Access logon name or the computer's
logon name?
 
T

Tony Wainwright

Ana

If "UserName" = "roma" Then
Me.Command42.Enabled = True
Me.Command43.Enabled = True
Me.Command44.Enabled = True
Else
Me.Command42.Enabled = False
Me.Command43.Enabled = False
Me.Command44.Enabled = False
End If

Tony
 
S

SRY

I tried the following with no avail....'******************** Code Start
**************************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If ( lngX > 0 ) Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = vbNullString
End If
End Function
'******************** Code End **************************Private Sub
Form_Open(Cancel As Integer)
DoCmd.Maximize
If fOSUserName = "roma" Then
Me.Command42.Enabled = True
Me.Command43.Enabled = True
Me.Command44.Enabled = True
End If
End Sub
 
W

Wayne Morgan

Did you step through the code to see what was being returned by the
function? Where did you place the function, in the forms code or in a
separate module? Did you get any error messages? What is your operating
system?

I just tried the function and it works ok.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top