connecting to ms access with vb6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #16
    That's ok, Yoda...

    Let's start from the top:

    (1)What part of access are you stuck in?

    (2)You should get familiar with access first if you are goping to use it as a back-end (database).

    (3)VB, as your front-end (Form or GUI), should know what is happening in the back-end.

    (4)You may be waiting for data and cannot see a thing or if you are adding, Yodamania will be empty if youare not properly communicating to it.

    (5)Did you make a table called Yodamania yet?

    Comment

    • yoda
      Contributor
      • Dec 2006
      • 291

      #17
      i'm not stuck in access, i'm familiar with access, to know how to make one and how to add information to it. i know how to use vb 6 mostly not all but the basics
      maybe but i don't think so there's the problem with my_database thing in the code when i debug it it says thats the problem and i'm not skill in this type of stuff. and yes i have made the table Yodamania.

      Please help no hurry though i won't be here this weekend.

      Yoda

      Comment

      • vijaydiwakar
        Contributor
        • Feb 2007
        • 579

        #18
        Sorry i've not gone through the discusion at all if u pls explain thy problem in detail i'll try to solve it
        bye

        Comment

        • yoda
          Contributor
          • Dec 2006
          • 291

          #19
          Originally posted by vijaydiwakar
          Sorry i've not gone through the discusion at all if u pls explain thy problem in detail i'll try to solve it
          bye
          the problem is i want to add to the database through VB 6.0 and i've tried a lot of things but so far its not working. there are two text boxs called User id and password and i would like that info transfered to a database called Yodamanina to a table called yoda.

          if u could help thanks.

          Comment

          • yoda
            Contributor
            • Dec 2006
            • 291

            #20
            can u people plz help me its really buging me!!!!!!!!!

            Yoda

            Comment

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

              #21
              I see...

              Let's go into your Username and Password first. We'll put the actual interaction to Yoda database on the back burner for now until you can get a working password, how's that for a deal?

              VB has a wonderful Username and Password form you can use. Assuming you have a Splash screen, which is a pretty good idea, by the way, if you need to better present your application. You probably already know that:

              (1) Run VB, choose project, add form, select Splash Screen

              (2) You do not need to rename your splash, simply go to its properties and make it your Start up form (should help with the code added here)

              (3) Go into the code automatically generated by Microsoft for this Splash Screen, delete everything and add below code. I have not commented too much, pretty basic though, please write if you need to know more about it


              Code:
              
              Option Explicit
              
              Private Sub Cancel_Click() 'Cancel button, just in case you need to get out
              End
              End Sub
              
              Private Sub Form_Load() 'Add your name or copyright info to this
                  lblVersion.Caption = "Version " & App.Major & "." & App.Minor & "." & App.Revision
                  lblProductName.Caption = App.Title [B]'Simply Yoda [/B] should be good here
              End Sub
              
              
              Private Sub Start_Click()
              frmSplash.Visible = False
              Login.Visible = True
              End Sub
              I merely modified Microsoft's code to reflect what I wanted. You will need 2 buttons:

              (a) Call a button Cancel, call the other Start

              (b) In above Start button command reflect visibility for the Splash Screen (frmSplash) to False

              (c) You can jump the gun here by adding a command for the password form you will add later, notice Login.Visible = True in above code

              What this means is when you click the Start button, Splash Screen goes and your wonderful Login form appears. Please forgive me for explaining too much, just making sure you get it.

              Now, at the risk of running out of room here, I'll jump to a new post with code for Login form...

              Comment

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

                #22
                ...the Login form is also pretty basic:

                (1)Run VB,

                (2)go to project,

                3)add from,

                (4)choose Log in Dialog

                Again, delete everything, then add the code below, also generated by Microsoft, I modified for today's use. Also delete my 'comments as you wish:

                Code:
                Option Explicit
                
                Public LoginSucceeded As Boolean
                
                Private Sub cmdCancel_Click() 'button added by Microsoft
                    LoginSucceeded = False 'Micorsoft code
                    Me.Hide
                    Login.Visible = False 
                
                'Your form called [B]Login[/B] set to False for visibility if password is correct, your VB form that collects data from Yodamania table should be True for visibility
                
                    End Sub
                
                
                Private Sub cmdOK_Click() 'check for correct password
                    If txtPassword = "password1" Then 
                
                'change the password here if you do not like it, [B]Y045DA[/B], or something in that kind of a line
                
                        LoginSucceeded = True
                        Me.Hide
                        Login.Visible = False
                        About.Visible = True 
                
                '[B]About[/B] can be changed to the name of your VB form that will hold data from Yodamania table
                
                    Else
                        MsgBox "Sorry! Invalid Password, please try again.", , "Login" 
                
                '[B]Login[/B] is the name of your [B]Username and Password [/B] form, if you changed the name of your form, you'll need to change it in the code here too
                
                        txtPassword.SetFocus
                        SendKeys "{Home}+{End}"
                    End If
                End Sub
                Please note: If you originally added your VB form as Start up form, and did not have a splash screen, remember to change it, since you now have a Splash Screen and your Splash Screen is read as your Start up form.

                I urge you to write again if this does not make sense, or if you are ready to access Yodamania table.

                Good luck, Yoda!

                Dököll

                Comment

                • yoda
                  Contributor
                  • Dec 2006
                  • 291

                  #23
                  Originally posted by Dököll
                  I see...

                  Let's go into your Username and Password first. We'll put the actual interaction to Yoda database on the back burner for now until you can get a working password, how's that for a deal?

                  VB has a wonderful Username and Password form you can use. Assuming you have a Splash screen, which is a pretty good idea, by the way, if you need to better present your application. You probably already know that:

                  (1) Run VB, choose project, add form, select Splash Screen

                  (2) You do not need to rename your splash, simply go to its properties and make it your Start up form (should help with the code added here)

                  (3) Go into the code automatically generated by Microsoft for this Splash Screen, delete everything and add below code. I have not commented too much, pretty basic though, please write if you need to know more about it


                  Code:
                  
                  Option Explicit
                  
                  Private Sub Cancel_Click() 'Cancel button, just in case you need to get out
                  End
                  End Sub
                  
                  Private Sub Form_Load() 'Add your name or copyright info to this
                      lblVersion.Caption = "Version " & App.Major & "." & App.Minor & "." & App.Revision
                      lblProductName.Caption = App.Title [B]'Simply Yoda [/B] should be good here
                  End Sub
                  
                  
                  Private Sub Start_Click()
                  frmSplash.Visible = False
                  Login.Visible = True
                  End Sub
                  I merely modified Microsoft's code to reflect what I wanted. You will need 2 buttons:

                  (a) Call a button Cancel, call the other Start

                  (b) In above Start button command reflect visibility for the Splash Screen (frmSplash) to False

                  (c) You can jump the gun here by adding a command for the password form you will add later, notice Login.Visible = True in above code

                  What this means is when you click the Start button, Splash Screen goes and your wonderful Login form appears. Please forgive me for explaining too much, just making sure you get it.

                  Now, at the risk of running out of room here, I'll jump to a new post with code for Login form...

                  VB 6.0doesn't like this: "lblVersion.Cap tion" in where u put it.

                  Comment

                  • yoda
                    Contributor
                    • Dec 2006
                    • 291

                    #24
                    Originally posted by Dököll
                    ...the Login form is also pretty basic:

                    (1)Run VB,

                    (2)go to project,

                    3)add from,

                    (4)choose Log in Dialog

                    Again, delete everything, then add the code below, also generated by Microsoft, I modified for today's use. Also delete my 'comments as you wish:

                    Code:
                    Option Explicit
                    
                    Public LoginSucceeded As Boolean
                    
                    Private Sub cmdCancel_Click() 'button added by Microsoft
                        LoginSucceeded = False 'Micorsoft code
                        Me.Hide
                        Login.Visible = False 
                    
                    'Your form called [B]Login[/B] set to False for visibility if password is correct, your VB form that collects data from Yodamania table should be True for visibility
                    
                        End Sub
                    
                    
                    Private Sub cmdOK_Click() 'check for correct password
                        If txtPassword = "password1" Then 
                    
                    'change the password here if you do not like it, [B]Y045DA[/B], or something in that kind of a line
                    
                            LoginSucceeded = True
                            Me.Hide
                            Login.Visible = False
                            About.Visible = True 
                    
                    '[B]About[/B] can be changed to the name of your VB form that will hold data from Yodamania table
                    
                        Else
                            MsgBox "Sorry! Invalid Password, please try again.", , "Login" 
                    
                    '[B]Login[/B] is the name of your [B]Username and Password [/B] form, if you changed the name of your form, you'll need to change it in the code here too
                    
                            txtPassword.SetFocus
                            SendKeys "{Home}+{End}"
                        End If
                    End Sub
                    Please note: If you originally added your VB form as Start up form, and did not have a splash screen, remember to change it, since you now have a Splash Screen and your Splash Screen is read as your Start up form.

                    I urge you to write again if this does not make sense, or if you are ready to access Yodamania table.

                    Good luck, Yoda!

                    Dököll

                    For some reason vb 6.0 doesn't like this under whatit is: "Login.Visi ble = False" it doesn't like Login at all thanks for helping me.!!!!!!!!

                    Yoda

                    Comment

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

                      #25
                      What happends when you add the code from both postings in?

                      Does anything work at all? For instance, do you ahve a Splash Screen?

                      Comment

                      • yoda
                        Contributor
                        • Dec 2006
                        • 291

                        #26
                        Originally posted by Dököll
                        What happends when you add the code from both postings in?

                        Does anything work at all? For instance, do you ahve a Splash Screen?
                        1 question before we get to that wat is a splash screen and i didn't put the codes in at the same time sorry.

                        i'm still kind of a newb at vb and acess.

                        Yoda thanks

                        Comment

                        • yoda
                          Contributor
                          • Dec 2006
                          • 291

                          #27
                          Originally posted by yoda
                          VB 6.0doesn't like this: "lblVersion.Cap tion" in where u put it.
                          it still doesn't work with all the code from what i can see "lblVerison.Cap tion" is wrong or something.

                          thanks for helping me out

                          Yoda

                          Comment

                          • yoda
                            Contributor
                            • Dec 2006
                            • 291

                            #28
                            sry another question of the code Y do u need to put Version in there with lblVersion.Capt ion.? and an error message pops up saying variable not defined.

                            thanks Yoda :)

                            Comment

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

                              #29
                              Hey Yoda!

                              Let's give it another whirl. We'll continue with more important stuff, like getting your Splash Screen to connect to your Passworsd form. I am going to add the code again, this time without comments. All you'll need to do is copy and paste, ok.



                              SPLASH SCREEN


                              Your Splash Screen Code is simpler now. Again Delete what you have, make sure your Splash Screen form is called frmSplash:


                              (1)Add 1 command button, name it Cancel

                              (2Add another button, name it Start

                              (3)Add below code to your Splash Screen form called frmSplash

                              Code:
                              Option Explicit
                              
                              Private Sub Cancel_Click()
                              End
                              End Sub
                              
                              
                              Private Sub Start_Click()
                              frmSplash.Visible = False
                              Login.Visible = True
                              End Sub
                              Save and run the code to make sure the Splash Screen works, then move on to next step (This form should be your Start up form)

                              (a)Right-click on frmSplash,

                              (b)go to Properties and make frmSplash your Start up form



                              Moving on...


                              LOGIN SCREEN


                              Let's now go into your Password form, make sure it is called Login

                              You will not need any additional buttons here, our good friend Bill Gates and Co thought this through for us...

                              Again, Delete what you have Login, and add below code:

                              Code:
                              Option Explicit
                              
                              Public LoginSucceeded As Boolean
                              
                              Private Sub cmdCancel_Click()
                                  LoginSucceeded = False
                                  Me.Hide
                                  Login.Visible = False
                              End Sub
                              
                              
                              Private Sub cmdOK_Click()
                                  
                                  If txtPassword = "password1" Then
                                      LoginSucceeded = True
                                      Me.Hide
                                      Login.Visible = False
                                      About.Visible = True
                                  Else
                                      MsgBox "Sorry! Invalid Password, please try again.", , "Login"
                                      txtPassword.SetFocus
                                      SendKeys "{Home}+{End}"
                                  End If
                              End Sub
                              If you did not change anything in the code and used it as is, you should be all set Yoda. Keep the password as password1 for now, just to be sure you're not toying with the code, at least until all works well at your end of it. Deal!

                              Comment

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

                                #30
                                ...ok,

                                Whatever name you chose for the form you will be using to add data to your Yodamania table, let's change it to something else. This is to avoid confusion:

                                (1)Go to that form you created

                                (2)Right-click on the form name through its properties window

                                (3)Change it to About

                                Notice: About was included in your Login form code

                                Go into the code for About, Delete everything you have, then add the below in order to add data to Yodamania table:


                                ABOUT SCREEN

                                If you already added 5 Textboxes, move on to the code, if not, add 5 Textboxes

                                (a) Text1
                                (b) Text2
                                (c) Text3
                                (d) Text4
                                (e) Text5

                                Go to your C: Drive, make a folder named DataMining
                                Copy and Paste your Yoda.mdb database to DataMining
                                (Very Important)

                                The code below is set to find Yoda.mdb in that folder...

                                Assuming you have a button named subt on About form, Copy and Paste this code, my friend. Be sure Values, in the code stays on the same line as UserID and Text1, ok

                                Code:
                                Private Sub subt_Click()   
                                
                                        Dim my_database As Database
                                        Set my_database = OpenDatabase("C:\DataMining\Yoda.mdb")
                                        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
                                
                                
                                Text1.Text=""
                                Text2.Text=""
                                Text3.Text=""
                                Text4.Text=""
                                Text5.Text=""
                                
                                
                                End Sub

                                (1)Run the code try adding to Yodamania.

                                (2)Make sure Yoda.mbd is closed.

                                (3)After adding data through Text1, Text2, etc...

                                (4)Open Yoda.mdb from your DataMining folder on ypur C: drive and see if what you typed in is there, if so, you're on your way :-)

                                Comment

                                Working...