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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows NT Logon 2

Status
Not open for further replies.

JCridland

Technical User
Jul 2, 2001
32
0
0
US
I have a database on which I have a module that picks up the NT use ID:
GetNetworkUser
Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String, strerror As String

strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)

If lngX <> 0 Then
fOSUserName = left$(strUserName, lngLen - 1)
Else
fOSUserName = &quot;&quot;
End If

'if null then tell the user that no valid log-in was captured
If fOSUserName = &quot;&quot; Then
strerror = &quot;No Valid user id was detected!&quot; & vbCrLf & vbCrLf
strerror = strerror & &quot;Are you logged into Novell?&quot; & vbCrLf

MsgBox strerror, vbCritical, strDbName


DoCmd.close &quot;frm_Splash&quot;

End If

End Function

I then have a form that opens upon load that has a field that captures that userID.

Based on the ID result, I want the database to then open the appropriate switchboard. I have a table of users and their associated rights and wrote the following but it isn't working.

Private Sub Form_Load()

Me.Caption = &quot;Please Wait...Starting Application&quot;
Me!continue_label.Visible = False

DoCmd.RunSQL &quot;DELETE GL8_BudgetAndHistory.* FROM GL8_BudgetAndHistory;&quot;
DoCmd.RunSQL &quot;INSERT INTO GL8_BudgetAndHistory SELECT GL8_BudgetAndHistory1.* FROM GL8_BudgetAndHistory1;&quot;


If DCount(&quot;[fldID]&quot;, &quot;westek users&quot;, &quot;[fldID]=[forms]![frm_splash]![cUser]&quot;) = 0 Then
MsgBox &quot;You are not a valid user of this application.&quot;, vbCritical, &quot;Invalid User&quot;
Quit
Else

Dim uPass As String
uPass = DLookup(&quot;[fldDepartment]&quot;, &quot;westek users&quot;, &quot;[fldID]=[forms]![frm_splash]![cUser]&quot;)
If uPass = &quot;Admin&quot; Then
DoCmd.OpenForm &quot;Switchboard&quot;
ElseIf uPass = &quot;Sales Mgmt&quot; Then
DoCmd.OpenForm &quot;Sales Switchboard&quot;
DoCmd.OpenForm &quot;Marketing Switchboard&quot;
ElseIf uPass = &quot;Materials&quot; Then
DoCmd.OpenForm &quot;Materials Switchboard&quot;
ElseIf uPass = &quot;Fiber&quot; Then
DoCmd.OpenForm &quot;Fiber Switchboard&quot;
ElseIf uPass = &quot;HR&quot; Then
DoCmd.OpenForm &quot;HR Switchboard&quot;
ElseIf uPass = &quot;Facilities&quot; Then
DoCmd.OpenForm &quot;Facilities Switchboard&quot;
ElseIf uPass = &quot;Planning&quot; Then
DoCmd.OpenForm &quot;Planning Switchboard&quot;
ElseIf uPass = &quot;MIS&quot; Then
DoCmd.OpenForm &quot;MIS Switchboard&quot;
ElseIf uPass = &quot;Corporate&quot; Then
DoCmd.OpenForm &quot;Switchboard&quot;
ElseIf uPass = &quot;QC&quot; Then
DoCmd.OpenForm &quot;QC Switchboard&quot;
ElseIf uPass = &quot;Engineering&quot; Then
DoCmd.OpenForm &quot;Engineering Switchboard&quot;
ElseIf uPass = &quot;Accounting&quot; Then
DoCmd.OpenForm &quot;Accounting Switchboard&quot;
ElseIf uPass = &quot;Production&quot; Then
DoCmd.OpenForm &quot;Production Switchboard&quot;
ElseIf uPass = &quot;Operations&quot; Then
DoCmd.OpenForm &quot;Materials Switchboard&quot;
DoCmd.OpenForm &quot;Fiber Switchboard&quot;
DoCmd.OpenForm &quot;Facilities Switchboard&quot;
DoCmd.OpenForm &quot;Planning Switchboard&quot;
DoCmd.OpenForm &quot;QC Switchboard&quot;
DoCmd.OpenForm &quot;Production Switchboard&quot;
DoCmd.OpenForm &quot;Engineering Switchboard&quot;

DoCmd.close &quot;frm_Splash&quot;
End If
End If
End Sub

I am not a programmer and am piecing code together and don't know how to tie the code behind the form to the module. bottom line, I don't want the users to have to logon on and that is why I am not using the Access security. Any ideas?

 
are you sure the field cUser on the form has the NT ID in it? can you see it?
 
dont know if it will help but here is the GetUserName code i use that i got from someone else. maybe you are not DECLARING the function GetUserName? i dunno...

Code:
Option Compare Database
Option Explicit

Declare Function GetUserName Lib &quot;advapi32.dll&quot; Alias &quot;GetUserNameA&quot; (ByVal lpBuffer As String, nSize As Long) As Long

Public Function GetUserLogonName() As String
'This function returns the Windows logon name of the user.
    Dim sUser As String
    Dim lRet As Long
    
        On Error GoTo ErrorHandler
'        If Error <> 64479 Then GoTo ErrorHandler
    
    sUser = Space(255)
    lRet = GetUserName(sUser, 255)
    sUser = Trim$(sUser)
    If Len(sUser) = 0 Then
        MsgBox &quot;Not logged on&quot;
    Else
        sUser = UCase(Left(sUser, Len(sUser) - 1))
        GetUserLogonName = sUser
    End If
    
 
Func_Exit:
    Exit Function
ErrorHandler:
    MsgBox &quot;Error # &quot; & Str(Err.Number) & &quot; was generated by &quot; & Err.Source & Chr(13) & Err.Description
    Resume Func_Exit
End Function
 
Thank you Ginger..

What it is currently doing is opening the wrong switchboard. The code on the form should direct the user to the appropriate switchboard based on their defined authority through a users table.

The module is definitely working as it is picking up their correct user ID (verified with our system admin).

What I don't understand how to do is to tie the fOSUserName to the westek users ID table. I tried changing the cUser field name to fOSUserName but that didn't work either.
If DCount(&quot;[fldID]&quot;, &quot;westek users&quot;, &quot;[fldID]=[forms]![frm_splash]![cUser]&quot;) = 0 Then
MsgBox &quot;You are not a valid user of this application.&quot;, vbCritical, &quot;Invalid User&quot;
Quit
Else

Dim uPass As String
uPass = DLookup(&quot;[fldDepartment]&quot;, &quot;westek users&quot;, &quot;[fldID]=[forms]![frm_splash]![cUser]&quot;)
we
 
so it sounds like you are not able to get the logon ID into that field in the form?

at the beginning of your form OnOpen code, go

me.cUser = GetUserLogonName()

make it visible so you can see if it worked.
then the rest of your code looks ok to me.
 
oh wait--no it doesnt. you need to put quotes around it. do this

If DCount(&quot;[fldID]&quot;, &quot;westek users&quot;,
&quot;[fldID] = '&quot; & me.cUser & &quot;'&quot;) = 0 Then

that is

single quote then double quote ...... double quote then single quote then double quote


it will end up i.e.

if dcount(&quot;[fldID]&quot;,&quot;westek users&quot;,&quot;[fldID] = 'vor1126') = 0

get it?
sorry i didnt see this before. i just checked my own code.
 
First of all THANK YOU SO MUCH GINGER. This is so close to being done. I got the following error when I made the changes you recommended:

&quot;Procedure declaration does not match description of even or procedure having same name.&quot;

This is what the entire code behind the form reads:

Option Compare Database 'Use database order for string comparisons
Option Explicit
'Copyright 2001, Westek Electronics, Inc. All rights reserved.

Private Sub Form_Activate()
DoCmd.Maximize
DoCmd.ShowToolbar &quot;Web&quot;, acToolbarNo

End Sub
Private Sub Form_Load()

Me.Caption = &quot;Please Wait...Starting Application&quot;
Me!continue_label.Visible = False

DoCmd.RunSQL &quot;DELETE GL8_BudgetAndHistory.* FROM GL8_BudgetAndHistory;&quot;
DoCmd.RunSQL &quot;INSERT INTO GL8_BudgetAndHistory SELECT GL8_BudgetAndHistory1.* FROM GL8_BudgetAndHistory1;&quot;

Dim rctOriginal As adhTypeRect
Call adhScaleForm(Me, 640, 461, 96, 96, rctOriginal)
Application.SetOption &quot;Confirm Record Changes&quot;, False
Application.SetOption &quot;Confirm Document Deletions&quot;, False
Application.SetOption &quot;Confirm Action Queries&quot;, False

End Sub
Private Sub Form_Open()

Me.cUser = GetUserLogonName()

If DCount(&quot;[fldID]&quot;, &quot;westek users&quot;, &quot;[fldID]= '&quot; & Me.cUser & &quot;'&quot;) = 0 Then
MsgBox &quot;You are not a valid user of this application.&quot;, vbCritical, &quot;Invalid User&quot;
Quit
Else

Dim uPass As String
uPass = DLookup(&quot;[fldDepartment]&quot;, &quot;westek users&quot;, &quot;[fldID]=[forms]![frm_splash]![cUser]&quot;)
If uPass = &quot;Admin&quot; Then
DoCmd.OpenForm &quot;Switchboard&quot;
ElseIf uPass = &quot;Sales Mgmt&quot; Then
DoCmd.OpenForm &quot;Sales Switchboard&quot;
DoCmd.OpenForm &quot;Marketing Switchboard&quot;
ElseIf uPass = &quot;Materials&quot; Then
DoCmd.OpenForm &quot;Materials Switchboard&quot;
ElseIf uPass = &quot;Fiber&quot; Then
DoCmd.OpenForm &quot;Fiber Switchboard&quot;
ElseIf uPass = &quot;HR&quot; Then
DoCmd.OpenForm &quot;HR Switchboard&quot;
ElseIf uPass = &quot;Facilities&quot; Then
DoCmd.OpenForm &quot;Facilities Switchboard&quot;
ElseIf uPass = &quot;Planning&quot; Then
DoCmd.OpenForm &quot;Planning Switchboard&quot;
ElseIf uPass = &quot;MIS&quot; Then
DoCmd.OpenForm &quot;MIS Switchboard&quot;
ElseIf uPass = &quot;Corporate&quot; Then
DoCmd.OpenForm &quot;Switchboard&quot;
ElseIf uPass = &quot;QC&quot; Then
DoCmd.OpenForm &quot;QC Switchboard&quot;
ElseIf uPass = &quot;Engineering&quot; Then
DoCmd.OpenForm &quot;Engineering Switchboard&quot;
ElseIf uPass = &quot;Accounting&quot; Then
DoCmd.OpenForm &quot;Accounting Switchboard&quot;
ElseIf uPass = &quot;Production&quot; Then
DoCmd.OpenForm &quot;Production Switchboard&quot;
ElseIf uPass = &quot;Operations&quot; Then
DoCmd.OpenForm &quot;Materials Switchboard&quot;
DoCmd.OpenForm &quot;Fiber Switchboard&quot;
DoCmd.OpenForm &quot;Facilities Switchboard&quot;
DoCmd.OpenForm &quot;Planning Switchboard&quot;
DoCmd.OpenForm &quot;QC Switchboard&quot;
DoCmd.OpenForm &quot;Production Switchboard&quot;
DoCmd.OpenForm &quot;Engineering Switchboard&quot;

DoCmd.close &quot;frm_Splash&quot;
End If
End If
End Sub




 
same thing with this line:

uPass = DLookup(&quot;[fldDepartment]&quot;, &quot;westek users&quot;, &quot;[fldID]=[forms]![frm_splash]![cUser]&quot;)


make it

...&quot;[fldID]='&quot;&me.cUser&&quot;'&quot;)

also sorry--my function is called GetUserLogonName() your's is fOSUserName i think...you have to change

Me.cUser = GetUserLogonName()

at the beginning of your form OnOpen to your function name instead. It is looking for something called GetUserLogonName() but you don't have such anything called that.

so if this doesnt work---i dont really get all the GetUserLogonName() code, so if you dont really care exactly what it says maybe you could just copy mine and replace yours. I dont know if yours is ok or not. to make sure i guess, make your text box cUser on the form be visible and see if it has your logon id in it when you open it. does it?

if this all still doesnt work, you might wanna put msgbox uPass after that dlookup and see what uPass contains.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top