We help IT Professionals succeed at work.

Set Password and create tbl from vb

CraigLazar
CraigLazar asked
on
Hi
I have this code which i am using to create a access2000 database. It works well except i
now need to create it and set the password up and then i need to create a table in the database.
So i have the first part working to create the db file. This is the code i am using to create it
    Dim catTmp As New ADOX.Catalog
    Dim tmpUser As New ADOX.User
    ' Delete the database if it exists
    On Error Resume Next
    Kill strPath
    On Error GoTo PROC_ERR
    ' The Create method of the ADOX.Catalog
    '     object
    ' creates a new database.
    catTmp.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath
   
   
Then i tried this line and it did not work
Call tmpUser.ChangePassword("", "password")

I think it has to do with opening the db thru vb in exclusive mode

thanx allot


Craig

Comment
Watch Question

Commented:
Do you know if the PROC_ERR procedure ever gets executed? I have noticed in the past that the kill method takes some time to execute, resulting in errors when the new database is created. To get around that error, a loop was placed in the code using dir to check that the file was truly deleted from the drive prior to creating it again. This may not be the answer to your question.
Senior .Net Consultant
CERTIFIED EXPERT
Top Expert 2016
Commented:
Use this:

catTmp.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath & ";Jet OLEDB:Database Password=MyDbPassword;"

Author

Commented:
thanx guys i will give it  a bash

:)

Craig

Author

Commented:
HI Emoreau
Thanz allot that worked great, one last question if u do not mind - how can i create a table now once the db is created - do u have a sample for me please ?

thanx allot

Craig

Author

Commented:
Great thanx again
Éric MoreauSenior .Net Consultant
CERTIFIED EXPERT
Top Expert 2016

Commented:

Author

Commented:
Hi Emoreau
I tired the code in the article but i am getting an eror on this line

>>> Cat.Tables.Append objTable

this is the error
"Object or provider is not capable of performing requested operation"

Do u have an article on maybe copying a table, cause maybe i can create a template table in my main db and then copy it into the newly created db than rather creating a table oin the fly - will be easier to maintian ?

thanx allot for the help - if u want more points for the help let me know

Have a good one

Cheers

Craig

Explore More ContentExplore courses, solutions, and other research materials related to this topic.