Results 1 to 2 of 2

Thread: Change an Access Database password, almost Resolved - Part 2 - copy tables?

  1. #1

    Thread Starter
    Hyperactive Member Trojan's Avatar
    Join Date
    Dec 2003
    Location
    Area 51
    Posts
    280

    Unhappy Change an Access Database password, almost Resolved - Part 2 - copy tables?

    for start, I most say the idea is not to change a database password, but to make a copy of it, with a New Password.

    Ps.
    I know the first database password....

    The Code:

    Private Sub CreateFirstDB(fileDB As String, dbStr As String, pass As String, Optional openTheDB As Boolean = False)
    Dim tblNewC As ADOX.Table, tblNewCS As ADOX.Table, tblNewST As ADOX.Table

    Set catDB = New ADOX.Catalog
    Set tblNewC = New ADOX.Table
    Set tblNewCS = New ADOX.Table
    Set tblNewST = New ADOX.Table

    catDB.Create dbStr & pass
    catDB.ActiveConnection = dbStr & pass


    tblNewC.Name = "Classes"
    tblNewC.Columns.Append "Cls_ID", adInteger
    tblNewC.Columns.Append "Cls_Name", adVarWChar, 10
    tblNewC.Columns.Append "Student_ID", adInteger
    tblNewC.Keys.Append "Cls_ID", adKeyPrimary Or adKeyUnique, "Cls_ID"

    tblNewCS.Name = "ClassesRange"
    tblNewCS.Columns.Append "Range_ID", adInteger
    tblNewCS.Keys.Append "Range_ID", adKeyPrimary Or adKeyUnique, "Range_ID"
    tblNewCS.Columns.Append "Range_Name", adVarWChar, 10
    tblNewCS.Columns.Append "Cls_ID", adInteger

    tblNewST.Name = "Students"
    tblNewST.Columns.Append "Student_ID", adInteger
    tblNewST.Keys.Append "Student_ID", adKeyPrimary Or adKeyUnique, "Student_ID"
    tblNewST.Columns.Append "Student_Name", adVarWChar, 30

    catDB.Tables.Append tblNewC
    catDB.Tables.Append tblNewCS
    catDB.Tables.Append tblNewST

    Set tblNewC = Nothing
    Set tblNewCS = Nothing
    Set catDB = Nothing

    If openTheDB Then OpenDB dbStr
    End Sub

    Public Function ChangePassword(NewPass As String) As Boolean
    Dim con As ADODB.Connection, cat As ADOX.Catalog
    Dim tbl As ADOX.Table
    fileDB = App.Path & "\tmpDB.mdb"
    CurConnection = CnnString & fileDB & ";Jet OLEDBatabase Password="
    CreateFirstDB fileDB, CurConnection, NewPass, False
    Set con = New ADODB.Connection
    con.Open CurConnection & NewPass ' Open the temp database & copy all the tables to it
    Set cat = New ADOX.Catalog
    Set cat.ActiveConnection = con
    For Each tbl In cat.Tables
    If UCase(tbl.Type) = "TABLE" Then
    If UCase(Left(tbl.Name, 4)) <> "MSYS" Then
    sql = "SELECT * INTO " & tbl.Name & " IN '" & fileDB & "' FROM " & tbl.Name
    'Debug.Print sql
    con.Execute sql
    End If
    End If
    Next tbl
    Set cat = Nothing
    Set con = Nothing
    ChangePassword = True
    End Function


    The problem is vb tells me this error:

    Table 'Classes' already exists.

    now the thing is I was trying to create a new database and then copy the tables to the new database with the new password....

    database is created withe the new password, tables are created in the same way as I have created the original database but no data is beign copied to the new database file with the above error...

    please help!

    Thanks inn advanced.
    MD5How To Detect Disk In Drive X?Time Tickerchanging the owner of a controlSystray HardCore

    • "Programming is like sex: one mistake and you have to support it for the rest of your life."
    • "A program is a spell cast over a computer, turning input into error messages."
    • "WARNING: Keyboard Not Attached. Press F10 to Continue."
    • "Why doesn't DOS ever say 'EXCELLENT command or filename!'"

  2. #2

    Thread Starter
    Hyperactive Member Trojan's Avatar
    Join Date
    Dec 2003
    Location
    Area 51
    Posts
    280

    Re: Change an Access Database password, almost Resolved - Part 2 - copy tables?

    Is it that hard to copy a table with all the data in it from one database to the other?
    MD5How To Detect Disk In Drive X?Time Tickerchanging the owner of a controlSystray HardCore

    • "Programming is like sex: one mistake and you have to support it for the rest of your life."
    • "A program is a spell cast over a computer, turning input into error messages."
    • "WARNING: Keyboard Not Attached. Press F10 to Continue."
    • "Why doesn't DOS ever say 'EXCELLENT command or filename!'"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width