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.