connecting vb with to access database without using adodc...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vikas1111
    New Member
    • Feb 2008
    • 122

    #1

    connecting vb with to access database without using adodc...

    This is the code which i have written.....
    [code=vb]
    Option Explicit
    Dim c As New ADODB.Connectio n
    Dim cm As ADODB.Command
    Dim rs As New ADODB.Recordset
    Private Sub regno_Change()
    c.Open ("Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=d:/Comion.mdb;Pers ist Security Info=false")
    rs.Open "select * from main_table", c, adOpenDynamic
    Me.regno.Text = rs(3)
    End Sub
    [/code]
    The error i am getting " User defined type not defined- -- for the first line of my code itself"
    Can anyone pls help me????
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Have you added the reference of ADO library ?

    Comment

    • vikas1111
      New Member
      • Feb 2008
      • 122

      #3
      Originally posted by debasisdas
      Have you added the reference of ADO library ?
      ya microsoft activex data object 2.library

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        Run in debug mode and check which line is throwing the error.

        Comment

        • vikas1111
          New Member
          • Feb 2008
          • 122

          #5
          Originally posted by debasisdas
          Run in debug mode and check which line is throwing the error.
          now error in this line
          c.Open ("Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=d:/Comion.mdb;Pers ist Security Info=false")

          The path which i have mentioned is correct....And i have already removed password..

          Comment

          • debasisdas
            Recognized Expert Expert
            • Dec 2006
            • 8119

            #6
            Try using this
            [code=vb]
            c.Open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=d:\Comio n.mdb;Persist Security Info=false"
            [/code]

            Comment

            • vikas1111
              New Member
              • Feb 2008
              • 122

              #7
              Originally posted by debasisdas
              Try using this
              [code=vb]
              c.Open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=d:\Comio n.mdb;Persist Security Info=false"
              [/code]
              Hi
              I changed it but i am getting the same error in the same line.... The error reads like this::::::
              Run time error 3705

              Comment

              • debasisdas
                Recognized Expert Expert
                • Dec 2006
                • 8119

                #8
                error in which line of code ?

                Comment

                • rizwan6feb
                  New Member
                  • Jul 2007
                  • 108

                  #9
                  If you are still having problem, try this

                  1. Paste ADODC control on your form
                  2. Connect it to your database using properties dialog
                  3. If it successfully connects to the database, copy the connection string and use it in place of the code which is creating problem
                  4. Remove the ADODC control from your form

                  Comment

                  • debasisdas
                    Recognized Expert Expert
                    • Dec 2006
                    • 8119

                    #10
                    To get the correct connection string it is better to use a UDL file .

                    Comment

                    • vikas1111
                      New Member
                      • Feb 2008
                      • 122

                      #11
                      Originally posted by rizwan6feb
                      If you are still having problem, try this

                      1. Paste ADODC control on your form
                      2. Connect it to your database using properties dialog
                      3. If it successfully connects to the database, copy the connection string and use it in place of the code which is creating problem
                      4. Remove the ADODC control from your form
                      hey Rizwan..
                      It worked thanks...
                      I want to know another thing.. If i want to link another column of the same table and in the same form with another text box then what should i do ?

                      Comment

                      • QVeen72
                        Recognized Expert Top Contributor
                        • Oct 2006
                        • 1445

                        #12
                        Hi,

                        You are not supposed to Open a Connection in a Change Event....
                        Try to add a ".bas" module Declare Connections as Public , In MDI Form Load Open the Connection..

                        Yes, the error 3705 is : Object already open..
                        So , Before Opening Check the State of the Connection..

                        [code=vb]
                        If c.State <> adStateOpen Then
                        Set c =Nothing
                        c.Open ("Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=d:\Comio n.mdb;Persist Security Info=false")
                        End If
                        [/code]

                        Comment

                        • debasisdas
                          Recognized Expert Expert
                          • Dec 2006
                          • 8119

                          #13
                          Just assign the column name or index of the column in the record set tothe text box.

                          Comment

                          • vikas1111
                            New Member
                            • Feb 2008
                            • 122

                            #14
                            Originally posted by debasisdas
                            Just assign the column name or index of the column in the record set tothe text box.

                            Ya i tried it but its not working ...

                            Comment

                            • debasisdas
                              Recognized Expert Expert
                              • Dec 2006
                              • 8119

                              #15
                              What is the error message ?

                              Comment

                              Working...