Wednesday, June 28, 2006

How to know if a User has access to a database..

I had a little action link on a form that allowed users to populate a field from a picklist. The data used for populating could come from two different data sources. If a user had access to a certain database, I wanted to display a picklist to data from that database, but if they didn't have access, then I wanted to display a picklist to data from a database that all users in our company have access to..

At first I tried to do If db.IsOpenByReplicaId.. I figured if it didn't open, then I would use the other db. But it gave an error when users who didn't have access to the database ran the code.

So, I wrote a function to trap the error. This little function will come in handy to lots of you I'm sure..

Here it is..

Function DBOpenByReplicaIDSafe(db As notesdatabase, Byval strServer$, Byval strRepID$) As Boolean
On Error 4060 Goto returnFalse
' generally better to find out exact error number, as opposed to ignoring unexpected errors that might not represent the type of failure you were expecting.
DBOpenByReplicaIDSafe = db.OpenByReplicaId(strServer, strRepID)
DBOpenByReplicaIDSafe = True
Exit Function
returnFalse:
DBOpenByReplicaIDSafe = False
Exit Function
End Function

0 comments: