Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with VB on click event please 1

Status
Not open for further replies.

DarkOne72

Technical User
Jun 14, 2002
210
US
Hello All --

Sorry to be a pain but I am in need of some assistance on a weird request:
I have a form that has a unbound text field showing the current user logged in the computer utilizing the fosUserName()
Code:
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)
        fosUserName = LCase(fosUserName)
    Else
        fosUserName = vbNullString
    End If
End Function

I also have a tblUsers with the USER_NT field and AccessLevelID field.
What I need to have happen is that when a user clicks on a button that if the USER_NT field on the form and the USER_NT field in the tblUSERS match AND the AccessLevelID = 1 that it will open up another form, if it doesn't match or equal 1 then it will give a message "Administrator Only"

Is this possible in VB on the on click event?

Thanks in adavnce....
 
How about if you change the text box to a combo box with a row source of tblUsers that includes the AccessLevelID column. You don't have to be able to see the column. You can then have code reference:
Code:
If Me.cboUser.Column(1) = 1 then


Duane
Hook'D on Access
MS Access MVP
 
Well I tried wha tyou said and kept the =fosUserName() in the default and it will only work if it shows a 1 in the combobox which I wanted it to show the current user and based on that showing whether or not the button would work. Maybe I am just messing it up trying to create it.
I created the combo box and put the default value to fosUserName() and record source was tblUSers and only had the AccessLevelID and USer_NT in the listing.

Thanks for the fast response though!!!
 
Well, I actually got it to work! I put the fosUserName() in the select statement for the USER_NT and then just hide the box from showing on the form.
i will then make another text box showing current user but thats all it does!
Thanks for all of your help! Great idea by the way!

Dark..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top