Results 1 to 21 of 21

Thread: [RESOLVED] DataBase Question

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Resolved [RESOLVED] DataBase Question

    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?

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: DataBase Question

    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


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3
    Hyperactive Member
    Join Date
    Oct 2007
    Location
    Indiana
    Posts
    295

    Re: DataBase Question

    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.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Re: DataBase Question

    Can you supply some code that will help me with this? I'm new to databases...

  5. #5
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: DataBase Question

    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.

    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

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Re: DataBase Question

    Caskbill,
    Can you help me with some code? I went to http://www.connectionstrings.com/ and i got lost...

  7. #7
    Hyperactive Member
    Join Date
    Oct 2007
    Location
    Indiana
    Posts
    295

    Re: DataBase Question

    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.

    Hope this helps

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: DataBase Question

    Moved to Database Development

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Re: DataBase Question

    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.
    Last edited by GDOG34; Aug 3rd, 2008 at 11:34 PM.

  10. #10
    Hyperactive Member
    Join Date
    Oct 2007
    Location
    Indiana
    Posts
    295

    Re: DataBase Question

    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.

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Re: DataBase Question

    Here is my code:
    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 get type mismatch on this line:
    Code:
    Set Myrs = Mydb.OpenRecordset("Version", dbOpenSnapshot)
    I attanced the database also. Why is it doing this?
    Attached Files Attached Files

  12. #12
    Hyperactive Member
    Join Date
    Oct 2007
    Location
    Indiana
    Posts
    295

    Re: DataBase Question

    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.

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Re: DataBase Question

    vb Code:
    1. Public Mydb As Database
    2. Public Myrs As Recordset
    3. Dim dbPath As String
    4. 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.

  14. #14
    Hyperactive Member
    Join Date
    Oct 2007
    Location
    Indiana
    Posts
    295

    Re: DataBase Question

    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
    vb Code:
    1. Public Mydb As Database
    2. Public Myrs As Recordset
    3. Dim dbPath As String
    4. 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.

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Re: DataBase Question

    Yep I Did it right...

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Re: DataBase Question

    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:
    1. Set Myrs = Mydb.OpenRecordset("Version", dbOpenSnapshot)
    Last edited by GDOG34; Aug 6th, 2008 at 12:27 PM.

  17. #17
    Hyperactive Member
    Join Date
    Oct 2007
    Location
    Indiana
    Posts
    295

    Re: DataBase Question

    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)

  18. #18

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Re: DataBase Question

    Nope, Still the same problem:
    Runtime error 13
    Type Mismatch
    On the same line..Will this work?:
    http://support.microsoft.com/kb/181542

  19. #19
    Hyperactive Member
    Join Date
    Oct 2007
    Location
    Indiana
    Posts
    295

    Re: DataBase Question

    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.

  20. #20

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Re: DataBase Question

    Thankyou! I had somethin else deleclared conflicting..

  21. #21

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Re: [RESOLVED] DataBase Question

    Works Perfect!
    Last edited by GDOG34; Feb 15th, 2009 at 11:10 PM.

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