• Passing password to Open method in sub (A2K)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Passing password to Open method in sub (A2K)

    Author
    Topic
    #371930

    Microsoft provided the following code to list who is in a database. I am trying to learn how I can provide a password to the Open method in the code. The password was created with the Tools, Security menu.

    I currently use LDBView, but wanted to explore this.

    Thanks,

    Randy

    =====================================================================
    Sub ShowUserRosterMultipleUsers()
    Dim cn As New ADODB.Connection
    Dim cn2 As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim i, j As Long

    cn.Provider = “Microsoft.Jet.OLEDB.4.0”
    cn.Open “Data Source=c:Northwind.mdb”

    cn2.Open “Provider=Microsoft.Jet.OLEDB.4.0;” _
    & “Data Source=c:Northwind.mdb”

    ‘ The user roster is exposed as a provider-specific schema rowset
    ‘ in the Jet 4 OLE DB provider. You have to use a GUID to
    ‘ reference the schema, as provider-specific schemas are not
    ‘ listed in ADO’s type library for schema rowsets

    Set rs = cn.OpenSchema(adSchemaProviderSpecific, _
    , “{947bb102-5d43-11d1-bdbf-00c04fb92675}”)

    ‘Output the list of all users in the current database.

    Debug.Print rs.Fields(0).Name, “”, rs.Fields(1).Name, _
    “”, rs.Fields(2).Name, rs.Fields(3).Name

    While Not rs.EOF
    Debug.Print rs.Fields(0), rs.Fields(1), _
    rs.Fields(2), rs.Fields(3)
    rs.MoveNext
    Wend

    End Sub
    =====================================================================

    Viewing 0 reply threads
    Author
    Replies
    • #592649

      According the helpfile in the section NewPassword Method :


      If object refers to a User object that is not yet appended to a Users collection, an error occurs. To set a new password, you must either log on as the user whose account you’re changing, or you must be a member of the Admins group. The Password property of a User object is write-only

      • #592654

        Thanks Francois, but I’m actually not trying to determine the password. I already know it – I’m trying to use the Sub provided on a database that has a password that I created. I want to know if the Open method can be provided a known password so it will not result in a run time error.

        Randy

        • #592664

          Did this help :
          Dim cn As New Connection
          cn.Connectionstring = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=databaseName;User ID=userName;Password=userPassword;”
          cn.open

    Viewing 0 reply threads
    Reply To: Passing password to Open method in sub (A2K)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: