Is there an easiest way where i can read from a password protected access database? Where i can read from it and put the contents read from a cell in a label? Also What is the easiest way to write to a password protected access database?
Using ADO will help you in that. But I am not experted in ADO (but in DAO) So please wait, because other members can help you....
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India
You'll need the password in order to open the database.
Once it's opened, you can read/write to it.
Once you open it, and want to read a record, open the table that contains the cell as a recordset. Then query the field that contains your data, and read it, assuming you know which record it is.
These aren't cells like you'd find in Excel. These are records which have fields, and data located in the field for the specific record being examined.
Once you have an understanding of this, you can then look at http://www.connectionstrings.com/ and click the Access link/icon in order to view connection strings specific to Ms Access. This includes at least one sample for accessing a password protected Access database there.
Please rate this post if it was useful for you!
Please try to search before creating a new post,
Please format code using [ code ][ /code ], and
Post sample code, error details & problem details
This should get you started. You must first add the Microsoft DAO 3.6 Object Library to your references if you haven't already done so.
The following code will open the database as named with the password as shown.
Code:
Public Mydb As Database
Public Myrs As Recordset
Dim dbPath As String
Dim A$
Private Sub Form_Load()
dbPath = "C:\MyDatabase.mdb" 'Your database name
'If your password was "TicTacToe" then your connect string would be:
Set Mydb = DBEngine.Workspaces(0).OpenDatabase(dbPath, True, False, ";pwd=TicTacToe") '1st true means open exclusive (false would be open shared), 2nd false means read/write (true would be read only)
End Sub
'If you have a table named "tblMyStuff" and one of the fields in that table is named "GreenThings" and the first record in that field is the word "Grass" then you would retrieve it this way:
Set Myrs = Mydb.OpenRecordset("tblMyStuff", dbOpenSnapshot)
Myrs.MoveFirst
A$ = Myrs!GreenThings
Debug.Print A$
Myrs.Close
Set Myrs = Nothing
'If you wanted to write the word "Tree" into the 3rd record in the Field "GreenThings":
Set Myrs = Mydb.OpenRecordset("tblMyStuff", dbOpenDynaset)
Myrs.MoveFirst
Myrs.MoveNext
Myrs.MoveNext
Myrs.Edit
Myrs!GreenThings = "Tree"
Myrs.Update
Myrs.Close
Set Myrs = Nothing
'When you are done and want to close the program, be sure to do this:
Mydb.Close
Set Mydb = Nothing
You should review all the database commands available, such as how to search for a specific record, and so on.
Did you forget to define Myrs as a recordset in your declarations section of the program?
I used the names so they can be recognized, Mydb (My database), and Myrs (My recordset), but you can define any 'name' you'd like.
You're not using the C:\Program Files as your App.path are you? While it's ok to put your program app there, you should not put your data file there. In fact, if you're using Vista, you cannot put your datafile there.
Just curious, how much security are you looking for with your password? Access passwords can be obtained fairly easily.
Yep, I already defined it. My app Path is actually on my desktop. I dont use Vista there is no pratical use for it. I i want to ssee something nice ill just look at the screenshots..Its useless its backwards...The password is just so some everyday JOE SMITH will open it.
The problem might be that your app.path is your desktop. Maybe try putting the database in a folder directly on your C: drive and see if that makes a difference. If it works then you'll know it can't be the desktop.
And just to verify, you do have the declarations in the declarations section of the form, and not in one of the subs such as the form_load event?
Originally Posted by GDOG34
vb Code:
Public Mydb As Database
Public Myrs As Recordset
Dim dbPath As String
Dim A$
Yep, I already defined it. My app Path is actually on my desktop. I dont use Vista there is no pratical use for it. I i want to ssee something nice ill just look at the screenshots..Its useless its backwards...The password is just so some everyday JOE SMITH will open it.
Hmmmm, running out of ideas. Maybe the table named "Version" is causing a problem. Any chance you've got a variable named "Version" somewhere else in your program? Maybe defined as an interger or something.
Maybe open the dB with Access and change the table name to something more generic. See if that helps.
You can also try without creating a snapshot.
Set Myrs = Mydb.OpenRecordset("Version")
or else try this:
Set Myrs = Mydb.OpenRecordset("Version", dbOpenDynaset)
Are you also using ADO in your project? If so then that could be the problem.
I put in the ActiveX reference in and get the same error. If you're not using ADO then remove the "Microsoft ActiveX Data Objects x.xx Library". If you are also using ADO, then go to Project, References, and click on the "Microsoft DAO 3.6 Object Library", then click the up priority button to position it above the ActiveX library.