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?
Printable View
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....:)
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.
Can you supply some code that will help me with this? I'm new to databases...
Goto this page for a tutorial on ADO, or ActiveX Data Objects - communicating with databases through VB6: http://www.vbforums.com/showthread.php?t=337051#ado
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.
Caskbill,
Can you help me with some code? I went to http://www.connectionstrings.com/ and i got lost...
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.
You should review all the database commands available, such as how to search for a specific record, and so on.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
Hope this helps
Moved to Database Development
What Format Does The Database Have To Been In? Because I get a unreconized format error. Currently my database is in Access 2000 file format.
Make sure you've loaded the DAO 3.6 library. That will read Access 2000 type databases.
The DAO 3.51 library is for Access97 type file formats.
Here is my code:
I get type mismatch on this line:Code:'Set The Registry Path And Password
dbPath = App.Path & "\Registry\Registry.mdb" 'Your database name
'The Password Is Preset To cypexosa
Set Mydb = DBEngine.Workspaces(0).OpenDatabase(dbPath, True, False, ";pwd=cypexosa") '1st true means open exclusive (false would be open shared), 2nd false means read/write (true would be read only)
'Open The Version Information In The Registry
Set Myrs = Mydb.OpenRecordset("Version", dbOpenSnapshot)
'Now Select The Type Of Version Information To Show
Myrs.MoveFirst
A$ = Myrs!VersionT
'Get The Current Version From The Registry
BuildInfo.Caption = "CypexOS© Advance Server " & A$
Myrs.Close
Set Myrs = Nothing
I attanced the database also. Why is it doing this?Code:Set Myrs = Mydb.OpenRecordset("Version", dbOpenSnapshot)
It works fine for me.
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.vb Code:
Public Mydb As Database Public Myrs As Recordset Dim dbPath As String Dim A$
Your code works perfectly on my computer.
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?
Quote:
Originally Posted by GDOG34
Yep I Did it right...
It's Not Fixing the type mismatch problem that I'm having on this end....
Runtime Error 13:
Type Mismatch
On The Following Line:
vb Code:
Set Myrs = Mydb.OpenRecordset("Version", dbOpenSnapshot)
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)
Nope, Still the same problem:
Runtime error 13
Type Mismatch
On the same line..Will this work?:
http://support.microsoft.com/kb/181542
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.
That should do it.
Thankyou! I had somethin else deleclared conflicting..
Works Perfect!