[AccessD] AutoExec Macro Question

Gustav Brock gustav at cactus.dk
Thu Mar 6 12:01:12 CST 2003


Hi Susan

I would certainly cut it down to this:

  Public Function basLoad() as Boolean

as you do not return a connection.

Also, add a return value:

  ...
  basLoad = True
  ex:
     Exit Function
  ...

/gustav


> Here's the code:

> Public Function basLoad() As ADODB.Connection
> On Error GoTo eh

> 'sbz 11/20/02 based on code from Mark Field.

> 'this code creates a connection to the SQL Server database using an
> application role.
> 'When the code is run, the user stops having permissions assigned to
> themselves as a user
> 'and takes on the permissions assigned to the role.  
> 'the user stays connected in the application role until the connection
> to sql server is
> 'terminated, which will most likely be on close of the application.

> Dim cnn As ADODB.Connection


>     Set cnn = New ADODB.Connection
>     Set cnn = CurrentProject.Connection
    
>     cnn.Execute ("EXEC sp_setapprole 'Name_of_application_role',
> {Encrypt N 'password'}, 'odbc'")

> ex:
>    Exit Function
   
> eh:
>   mbAppCnxnOpen = False

>   Set mAppCnxn = Nothing

>   If Err.Number = -2147467259 Then
>     Err.Raise 55004, , "You currently cannot connect to the database
> server.  Please contact the OIS Help Desk 5-4564."
>   Else
>     MsgBox Err.Description
>   End If
    
>   GoTo ex
> End Function




More information about the AccessD mailing list