QueryModeChange - LS - Object Variable not set

Hello All,

I have this code on my form in QueryModeEvent.

Sub Querymodechange(Source As Notesuidocument, Continue As Variant)

Dim session As New NotesSession

Dim db As NotesDatabase

Dim acl As NotesACL

Dim entry As NotesACLEntry

Set db=session.CurrentDatabase

Set acl=db.ACL

Set entry=acl.GetEntry(session.UserName)



If Not ( Source.EditMode ) Then

	

	status = Source.FieldGetText( "EndStatus" )

	If (status="Running") And (entry.IsRoleEnabled("TapeLib"))=False Then

		Messagebox _

		("This back-up is available for browsing only - If you have a query on this back-up please contact HelpDesk.  Thank you." )

		

		continue= False

	End If

	

	If (status="Completed") And (entry.IsRoleEnabled("TapeLib"))=False Then

		Messagebox _

		("This back-up is available for browsing only - If you have a query on this back-up please contact HelpDesk.  Thank you." )

		

		continue= False			

	End If

	

End If

End Sub

If the document status is “Running” or “Completed” and I try to edit it, it doesn’t let me, and it displays the message - great! However, it a user does the same it comes up with “Object Variable not set” and lets them edit and save…

Does anyone know why?

No one, apart from Admin has the “[TapeLib]” role, which is correct.

Any help is really appreciated, as usual.

Thanks,

Hayley.

Subject: QueryModeChange - LS - Object Variable not set

The cause of your problem is most likely related to the user not being in the ACL in which case ‘entry’ will be null.

You should have error trapping / handling in your code so you can deal with these and know exactly where the error occurs. Here is a suggested code change with error handling added:


Dim session As New NotesSession

Dim db As NotesDatabase

Dim acl As NotesACL

Dim entry As NotesACLEntry

’ Error Handler

On Error Goto Error_Handler

Set db=session.CurrentDatabase

Set acl=db.ACL

Set entry=acl.GetEntry(session.UserName)

If Not ( Source.EditMode ) Then

status = Source.FieldGetText( “EndStatus” )

If (status=“Running”) And (entry.IsRoleEnabled(“TapeLib”))=False Then

Messagebox _

(“This back-up is available for browsing only - If you have a query on this back-up please contact HelpDesk. Thank you.” )

continue= False

End If

If (status=“Completed”) And (entry.IsRoleEnabled(“TapeLib”))=False Then

Messagebox _

(“This back-up is available for browsing only - If you have a query on this back-up please contact HelpDesk. Thank you.” )

continue= False

End If

End If

Exit Sub

Error_Handler:

Dim NewLine As String

NewLine = Chr(10) & Chr(13)

Messagebox "The following error occurred: " & NewLine & "Error number: " & Cstr(Err) & NewLine & "Line number: " & Cstr(Erl) & NewLine & "Description: " Error$, 0+16, “An error has occurred”

Exit Sub

Subject: RE: QueryModeChange - LS - Object Variable not set

Hello,

Thank you for the Error handling code. They are in the ACL. They are listed in a group with all the other users…? This group in the ACL is Person Group - Author.

Any other ideas?

Thanks.

Subject: RE: QueryModeChange - LS - Object Variable not set

If the person is in a group, the code will not work, because the ACL does not know who is in the group, only that the group has access.

To get around it for a specific user, I am assuming you would have to loop through the ACL entries and whenever you find a group name you will have to do a lookup to the server’s names.nsf to verify that the current user is in the group. Unfortunately I don’t have the time right now to give you sample code to accomplish this. sorry.

hth.

brandt

Subject: RE: QueryModeChange - LS - Object Variable not set

The code you’re using is looking for the specific username in the ACL which will fail because, as you said, the username is not there but a group name is.

You can use the ‘Evaluate’ function in LotusScript to call a Notes formula which will give you the result you want. Here’s another update to your code:


Dim session As New NotesSession

Dim db As NotesDatabase

Dim acl As NotesACL

Dim entry As NotesACLEntry

Dim EvalResult As Variant

Dim IsTapeLib As Integer

’ Error Handler

On Error Goto Error_Handler

Set db=session.CurrentDatabase

EvalResult = Evaluate(|@IsMember(“[TapeLib]”;@UserRoles)|)

If IsArray(EvalResult) Then

If EvalResult(0) = 1 Then

   ' This user is in the TapeLib role

   IsTapeLib = True

End If

End If

If Not ( Source.EditMode ) Then

status = Source.FieldGetText( “EndStatus” )

If (status=“Running”) And Not IsTapeLib Then

Messagebox _

(“This back-up is available for browsing only - If you have a query on this back-up please contact HelpDesk. Thank you.” )

continue= False

End If

If (status=“Completed”) And Not IsTapeLib Then

Messagebox _

(“This back-up is available for browsing only - If you have a query on this back-up please contact HelpDesk. Thank you.” )

continue= False

End If

End If

Exit Sub

Error_Handler:

Dim NewLine As String

NewLine = Chr(10) & Chr(13)

Messagebox "The following error occurred: " & NewLine & "Error number: " & Cstr(Err) & NewLine & "Line number: " & Cstr(Erl) & NewLine & "Description: " Error$, 0+16, “An error has occurred”

Exit Sub


Subject: RE: QueryModeChange - LS - Object Variable not set

Alex, thank you so much… this has worked.

Also, thanks to everyone who has replied.

Subject: Also…

Also…

You can further optimize your code by combining the check & messagebox into a single paragraph using the following example instead of seperate checks for status which return the same messagebox:

If (status=“Running” Or status=“Completed”) And Not IsTapeLib Then…

Subject: RE: QueryModeChange - LS - Object Variable not set

The error I am seeing now with the error handling is:

Error number :91

Line number : 17

Description: object variable not set

I’m not sure why?