Logging into multiple projects

Logging into multiple projects

Hey,
I'm having problem logging user into mutliple projects. In my workspace, I have a main project, witch contains a few sub-projects. I was trying to implement metods from this thread.
When I used herbertos code, I was getting message box saying "Invalid user identification!". When I make the user in the project, it works. But...I have 10 sub-projects already (more to come) and quite a lot of users, witch makes creating user by user a bit time consuming.
I also tried modified version of his code, witch should create new users and log them into projects. But...didnt work. Function CreateUser in VBA somehow does not want to create a new user, if it is executed via zenon runtime. CreateUser works if I run it via debug mode in VBA.
Any help is appreciated!
Modified code:
VBA Code:
Option Explicit

Dim WithEvents myPwd As Passwords

'event fired on starting runtime
Private Sub Project_Active()

'create object for "UserChange" event
Set myPwd = thisProject.Passwords
End Sub

'event fired when a user logged in
Private Sub myPwd_UserChange()

Dim iProjCount As Integer
Dim level, level1, level2, level3
Dim zUsername, zUserIden As String

zUsername = myPwd.loggedUser
zUserIden = myPwd.ItemUser(zUsername).Identification
level = myPwd.ItemUser(zUsername).level
level1 = myPwd.ItemUser(zUsername).level1
level2 = myPwd.ItemUser(zUsername).level2
level3 = myPwd.ItemUser(zUsername).level3

On Error GoTo Errorhandler

'go through all projects
For iProjCount = 0 To thisProject.Parent.Count - 1
'check if this is the integration project itself (no double login)
'MsgBox thisProject.Parent.Item(iProjCount).Name
If StrComp(thisProject.Guid, thisProject.Parent.Item(iProjCount).Guid) <> 0 Then
'check if the new user is the system user (logout)
If myPwd.loggedUser = "0000" Then
thisProject.Parent.Item(iProjCount).Passwords.Logoff
Else
'first create new user
thisProject.Parent.Item(iProjCount).Passwords.CreateUserEx zUserIden, zUsername, "", level, level1, level2, level3

'log in the user (from the integration project)
thisProject.Parent.Item(iProjCount).Passwords.Login (zUsername)

'check if the login was successful
If thisProject.Parent.Item(iProjCount).Passwords.loggedUser <> zUsername Then
'user could NOT be logged in
'write to CEL of integration project
thisProject.Parent.Item(0).Cel.WriteCelString ("User: """ & zUsername & """ could not be logged into project: " & thisProject.Parent.Item(iProjCount).Name)
End If
End If
End If
Next iProjCount
Exit Sub

Errorhandler:
'an error has occured
If err.Number <> 0 Then
'write to CEL of integration project
thisProject.Parent.Item(0).Cel.WriteCelString ("There was an error while trying to log into the project: " & thisProject.Parent.Item(iProjCount).Name)
Resume Next
End If
End Sub

'event fired on closing runtime
Private Sub Project_Inactive()

'release the created object
Set myPwd = Nothing
End Sub


This is a migrated post! Originally posted on 19.03.2012 by user jurijcadez. Please be aware that information can be outdated.

    Disclaimer

    This document governs the use of our Community Forum. By registering and using the platform, you accept these conditions.

    The COPA-DATA Community Forum serves to encourage the exchange of information and experience about the zenon software between forum users respectively zenon users.

    Please mind that any published information on the Community Forum is the subjective opinion and view based on the experience and the level of knowledge of the author. COPA-DATA does not overtake any responsibility for the content and the accuracy of the shared information.

    Users of the Community Forum are encouraged to share only well-founded experiences and to point out any risks associated with the implementation of proposed solutions to problems. COPA-DATA at its absolute discretion, reserves the right to moderate the forum. In this connection COPA-DATA may remove any information containing false facts, potentially dangerous solutions, bad language or content that may insult, degrade or discriminate others. COPA-DATA may block a non-complying user from forum access if the user violated this provision.

    COPA-DATA reserves the right to change this document from time to time at own discretion.


    Ing. Punzenberger COPA-DATA GmbH
    Karolingerstraße 7b · 5020 Salzburg · Austria
    www.copadata.com