connecting to ms access with vb6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yoda
    Contributor
    • Dec 2006
    • 291

    #1

    connecting to ms access with vb6

    i've got a question is it pausible to put a date base like (access) in a project in vb.6.0 and how would i do it if pasueible.

    don't mind the spelling Yoda
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Originally posted by yoda
    i've got a question is it pausible to put a date base like (access) in a project in vb.6.0 and how would i do it if pasueible.

    don't mind the spelling Yoda
    Changing the title yoda because it will work better for others in a search

    Comment

    • yoda
      Contributor
      • Dec 2006
      • 291

      #3
      thanks


      willakawill :)

      Comment

      • willakawill
        Top Contributor
        • Oct 2006
        • 1646

        #4
        Originally posted by yoda
        thanks


        willakawill :)
        There is a lot to learn to achieve this. You can start by reading this page

        Comment

        • Dököll
          Recognized Expert Top Contributor
          • Nov 2006
          • 2379

          #5
          Hello Yoda!

          If you searched here and could not find an answer, here is a simple fix. I remember adding something similar here, been out of the game lately:

          (1) Start a brand new access database, if you haven't already
          (2) Call it Yoda, the system will add .mdb for you
          (3) Make a table called Yodamania, through design view
          (4) Add 5 fields, UserID, Name, Address, Phone, Email
          (5) Open your wonderful Yodamania table
          (6) Add some data in this table to reflect the column names

          Example:

          in UserID, type 12345,
          in Name, type Yodamania Dudette,
          in Address, type 321 Fantastico Blv, Nothingham, UK,
          in Phone, type 011-634-324-765-0987,
          in Email, type yodamania@yodam db.net

          Start a new VB project, form1, project1 is by default, no need to rename the project if you feel you can go on as is:

          (a) Drag 5 Textboxes to your form, namely Text1, Text2, and so on...
          (b) Add a command button, call it Seek
          (c) Add below code to this form of yours

          Code:
          'this is searching for existing data in your access
          Private Sub Seek_Click() 'this is your button
          Dim my_database As Database           'dimension database as database 
          Dim my_record As Recordset              'dimension recordset as recordset
          
          Set my_database = OpenDatabase("C:\DataMining\Yoda.mdb")  
          
          'You can change above path/folder name to location of your own access 
          'database
           
          'Going forward, above function will open the Yoda database 
          'Make your Yoda databse is closed
          
          Set my_record = my_database.OpenRecordset("select * from Yodamania where UserID like '" & Text1.Text & "'")    ' this is used to search by user id
          
             Do While Not my_record.EOF  
          
          'this function will keep searching for fields matching each textbox
          
                  Text1.Text = my_record.Fields("UserID")
                  Text2.Text = my_record.Fields("Name")
                  Text3.Text = my_record.Fields("Address")
                  Text4.Text = my_record.Fields("Phone")
                  Text5.Text = my_record.Fields("Email")
          
           my_record.MoveNext 
             Loop
             my_database.Close
          End Sub
          Yoda if this does not get you started, please write again. I added this quickly for you, it should work straight away. Reply if you need more assistance.

          In a bit!

          Dököll

          Comment

          • Dököll
            Recognized Expert Top Contributor
            • Nov 2006
            • 2379

            #6
            Nuts, I did not see your replies here WillAkaWill...

            Please carry on Yoda, and good luck :-)

            Comment

            • willakawill
              Top Contributor
              • Oct 2006
              • 1646

              #7
              Originally posted by Dököll
              Nuts, I did not see your replies here WillAkaWill...

              Please carry on Yoda, and good luck :-)
              No problem D
              You want to write an entire ADO tutorial for our mr yoda I'm right behind you :)
              Go for it.

              Comment

              • yoda
                Contributor
                • Dec 2006
                • 291

                #8
                thanks every 1 i'll get right on it when i have time right now i've got a lot of home work from school so i will get back to u guys.

                Yoda

                Comment

                • yoda
                  Contributor
                  • Dec 2006
                  • 291

                  #9
                  sry but thats not all what if i wanted the stuff typed in to the text box's and save on the date base ?

                  Yoda :)

                  Comment

                  • Dököll
                    Recognized Expert Top Contributor
                    • Nov 2006
                    • 2379

                    #10
                    Originally posted by willakawill
                    No problem D
                    You want to write an entire ADO tutorial for our mr yoda I'm right behind you :)
                    Go for it.
                    I've been snoozing at work, new management, work from home, that sort of thing, just catching up with what I've missed thus far in our wonderful forum. Hopefully you are well :-)

                    Comment

                    • Dököll
                      Recognized Expert Top Contributor
                      • Nov 2006
                      • 2379

                      #11
                      Yoda, you asked for it, here's the real deal, this is a lot simpler than the previous code:

                      (1) Leave your wonderful Yoda.mdb as is
                      (2) The code I gave you can be used to retrieve what you hope to enter
                      (My apologies, by the way, for the confusion, I thought you could not see data added in)
                      (3) Add a new button, call it subt
                      (4) Add Below code, please read it so you understand what is happening
                      (I could have a screw loose, so be careful)

                      Code:
                      Private Sub subt_Click()   ' Here is your button
                      'this function will load entry into your Yoda database
                      
                              Dim my_database As Database 
                      
                      'still dimension as database to VB knows what youa re attempting
                      
                              Set my_database = OpenDatabase("C:\DataMining\Yoda.mdb")
                      
                      'Keep below on the same line from my_database to '")", you are Excecuting this action to Yoda.mdb.  Values from your Text1, 2, ect.  Will entetred in UserID and so on...(Straight line Yoda, ok)
                      
                              my_database.Execute "insert into Yoda.Yodamania(UserID, Name, Address, Phone,Email) Values('" & Text1.Text & "','" & Text2.Text & "' , '" & Text3.Text & "' , '" & Text4.Text & "','" & Text5.Text & "')"
                              my_database.Close ' 
                        
                      'You will need to clear your textboxes here, do somehting like
                      
                      'Text1.Text="" for all your textboxes
                      
                      End Sub  'You should be all set
                      Please send us a note if this does not work. Again, you Access database must remain closed at all times during your entries through VB. Have fun!

                      Comment

                      • yoda
                        Contributor
                        • Dec 2006
                        • 291

                        #12
                        sry but problem "my_databas e As Database" in code i will see wat i can do.

                        Yoda :)

                        Comment

                        • yoda
                          Contributor
                          • Dec 2006
                          • 291

                          #13
                          sry another question do i still u the same code from the reply before yes/no

                          Yoda :)

                          Comment

                          • willakawill
                            Top Contributor
                            • Oct 2006
                            • 1646

                            #14
                            Originally posted by yoda
                            sry another question do i still u the same code from the reply before yes/no

                            Yoda :)
                            Which part of your class is this project yoda?

                            Comment

                            • yoda
                              Contributor
                              • Dec 2006
                              • 291

                              #15
                              not part of my classes at all i just want to know? because i'm really new to access and have already tried connecting access to VB 6.0 before and lost the battle i gave up until now i will get it your guys help.

                              Thanks Yoda

                              Comment

                              Working...