MS ActiveX Data Control Object

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MA10
    New Member
    • May 2010
    • 10

    MS ActiveX Data Control Object

    I'm working with my access project using MS Visual Basic. However there's a problem occur when I used adodb.recordset . Most of the solutions that I searched needs me to download MS ActiveX Data Control Object. But, where can I download it? Or do you have other solution to solve this problem:

    rst As ADODB.Recordset
  • vb5prgrmr
    Recognized Expert Contributor
    • Oct 2009
    • 305

    #2
    Without seeing your code, the err.number, the err.description , and knowing the offending line, it is really hard for us to help you...



    Good Luck

    Comment

    • QVeen72
      Recognized Expert Top Contributor
      • Oct 2006
      • 1445

      #3
      Hi,

      You dont need to Download/Install ActiveX Dataobject.. It is already installed along with VB6.
      In you project add the dll in thie menu :
      Project >> References >> Microsoft Active X Data Objects 2.5 Libraray.

      Regards
      Veena

      Comment

      • MA10
        New Member
        • May 2010
        • 10

        #4
        Originally posted by QVeen72
        Hi,

        You dont need to Download/Install ActiveX Dataobject.. It is already installed along with VB6.
        In you project add the dll in thie menu :
        Project >> References >> Microsoft Active X Data Objects 2.5 Libraray.

        Regards
        Veena
        But i'm just using an ordinary vb i.e in the MS Access 2007. So,i can't do:
        Project >> References >> Microsoft Active X Data Objects 2.5 Libraray.

        Comment

        • MA10
          New Member
          • May 2010
          • 10

          #5
          Originally posted by vb5prgrmr
          Without seeing your code, the err.number, the err.description , and knowing the offending line, it is really hard for us to help you...



          Good Luck
          When I run the code,the compiling error said that the identifier under the cursor is not recognized.I felt weird coz my sister did almost the same programming and it works in MS Access 2007,but mine doesn't. She did the coding in MS 2000 and then upgrade to MS 2007.She said, she did experienced the same problem as mine and she changed something at the properties. Then everything is okay.But she forgot how

          Comment

          • vb5prgrmr
            Recognized Expert Contributor
            • Oct 2009
            • 305

            #6
            With 2k7, if I remember correctly you have the ability to save it in two different formats. You must save the database in the mdb format...



            Good Luck

            Comment

            • MA10
              New Member
              • May 2010
              • 10

              #7
              Originally posted by vb5prgrmr
              With 2k7, if I remember correctly you have the ability to save it in two different formats. You must save the database in the mdb format...



              Good Luck
              I haven't try it, but here is the code if u wanna have a look. B4 I forget,the compile error also said the user-defined type is not defined.What it mean actually?:

              Code:
              Private Sub cmdVw_Click()
              
                  Dim rst As ADODB.Recordset
                  Dim sCondition As String
                  
                  sCondition = "N"
                  Set rst = New ADODB.Recordset
                    
                  rst.ActiveConnection = CurrentProject.Connection
                  
                  rst.CursorType = adOpenDynamic
                  rst.LockType = adLockOptimistic
                  rst.Open "Patient"
                  
                  'Invalid MRN
                  Do Until rst.EOF
                  If Me.txtMRN <> rst![MRN] Then
                      sCondition = "T"
                  End If
                  rst.MoveNext
                  Loop
                  
                  'valid MRN
                  rst.MoveFirst
                  Do Until rst.EOF
                  If Me.txtMRN = rst![MRN] Then
                  sCondition = "M"
                  End If
                  rst.MoveNext
                  Loop
              
                  'MRN is null
                  rst.MoveFirst
                  Do Until rst.EOF
                  If Not IsNull(Me.txtMRN) Then
                  sCondition = "K"
                  End If
                  rst.MoveNext
                  Loop
                       
                  'both MRN and IC No are null
                  rst.MoveFirst
                  Do Until rst.EOF
                  If IsNull(Me.txtMRN) And IsNull(Me.txtICNo) Then
                  sCondition = "S"
                  End If
                  rst.MoveNext
                  Loop
                  
                  'both MRN and IC No are filled in
                  rst.MoveFirst
                  Do Until rst.EOF
                  If Not IsNull(Me.txtMRN) And Not IsNull(Me.txtICNo) Then
                  sCondition = "Z"
                  End If
                  rst.MoveNext
                  Loop
                  
                  If sCondition = "T" Then
                      MsgBox "Please key in a valid MRN", vbExclamation + vbOKOnly
                      txtMRN.SetFocus
                      txtMRN = Null
                      Exit Sub
                  End If
                  
                  If sCondition = "M" Then
                      DoCmd.OpenForm "Patient", , , _
                     "MRN='" & Me.txtMRN & "'"
                      DoCmd.Close acForm, "Main Form"
              
                      Exit Sub
                  End If
                  
                   If sCondition = "K" Then
                      MsgBox "Please key in a MRN", vbExclamation + vbOKOnly
                          Me.txtMRN.SetFocus
                      Exit Sub
                  End If
                  
                   If sCondition = "S" Then
                      MsgBox "Please choose MRN or IC No", vbExclamation + vbOKOnly
                      txtICNo.SetFocus
                      Exit Sub
                  End If
                  
                   If sCondition = "Z" Then
                      MsgBox "Please choose MRN OR IC No ONLY", vbExclamation + vbOKOnly
                          txtMRN = Null
                          Me.ICNo.SetFocus
                          txtICNo = Null
                      Exit Sub
                  End If
                     
              End Sub
              Last edited by Niheel; Jun 10 '10, 07:44 AM. Reason: Added code tags. Please use code tags to display code.

              Comment

              • QVeen72
                Recognized Expert Top Contributor
                • Oct 2006
                • 1445

                #8
                Hi,

                For Access2007, you have to add references here :

                Goto Form's Code Editor, and menu : Tools >> References
                Select "Microsoft Active X Data Objects 2.5 Libraray"

                And Declare :

                Dim RST As New ADODB.RecordSet

                Regards
                Veena

                Comment

                • vb5prgrmr
                  Recognized Expert Contributor
                  • Oct 2009
                  • 305

                  #9
                  Veena,

                  The OP is not using VB6 but using VBA from within MS Access itself.

                  MA10,

                  A User defined type error usually means that you are trying to access the properties of an object that has not been declared. Like if you declared your connection object in one sub and then tried to access it from another sub you would get that error as the object would be out of scope.



                  Good Luck

                  Comment

                  • MA10
                    New Member
                    • May 2010
                    • 10

                    #10
                    Originally posted by vb5prgrmr
                    Veena,

                    The OP is not using VB6 but using VBA from within MS Access itself.

                    MA10,

                    A User defined type error usually means that you are trying to access the properties of an object that has not been declared. Like if you declared your connection object in one sub and then tried to access it from another sub you would get that error as the object would be out of scope.



                    Good Luck
                    So how?I'm very blur right now

                    Comment

                    • vb5prgrmr
                      Recognized Expert Contributor
                      • Oct 2009
                      • 305

                      #11
                      Okay, lets say you have a control on Form1. Lets say it is a label named Label1. Then you have a module and in that module you have a sub. Lets say SetCaption. Now, when you do label1.caption an error like yours will happen because there is no reference to form1...
                      Code:
                      Public Sub SetCaption(strCap As String)
                      'Lable1.Caption = strCap 'this will cause error
                      Form1.Lable1.Caption = strCap 'this is correct
                      End Sub
                      This can also happen if you declare a variable in one procedure and try to access it from another procedure...
                      Code:
                      Private Sub OpenConn()
                      Dim Conn As New ADODB.Connection
                      '...
                      End Sub
                      
                      Private Sub UseConn()
                      Dim Rs As New ADODB.Recordset
                      Rs.Open strSQL, Conn 'an error occurs here because the connection object you declared in OpenConn went out of scope as soon as that sub was exited. To Fix, delcare the conn variable in the general declarations of the form/module.


                      Good Luck


                      [/code]

                      Comment

                      • MA10
                        New Member
                        • May 2010
                        • 10

                        #12
                        Originally posted by vb5prgrmr
                        Okay, lets say you have a control on Form1. Lets say it is a label named Label1. Then you have a module and in that module you have a sub. Lets say SetCaption. Now, when you do label1.caption an error like yours will happen because there is no reference to form1...
                        Code:
                        Public Sub SetCaption(strCap As String)
                        'Lable1.Caption = strCap 'this will cause error
                        Form1.Lable1.Caption = strCap 'this is correct
                        End Sub
                        This can also happen if you declare a variable in one procedure and try to access it from another procedure...
                        Code:
                        Private Sub OpenConn()
                        Dim Conn As New ADODB.Connection
                        '...
                        End Sub
                        
                        Private Sub UseConn()
                        Dim Rs As New ADODB.Recordset
                        Rs.Open strSQL, Conn 'an error occurs here because the connection object you declared in OpenConn went out of scope as soon as that sub was exited. To Fix, delcare the conn variable in the general declarations of the form/module.


                        Good Luck


                        [/code]
                        I still can't solve the problem...

                        Comment

                        • vb5prgrmr
                          Recognized Expert Contributor
                          • Oct 2009
                          • 305

                          #13
                          Okay, ... ... ... To resolve this, use proper error handling...
                          Code:
                          Private Sub MySub()
                          
                          On Error GoTo MySubError
                          
                          'code goes here
                          
                          Exit Sub
                          MySubError:
                          
                          MsgBox "Form/modulename.MySub " & Err.Number & ":" & Err.Description
                          resume' not recommended for anything but debugging
                          
                          End Sub
                          No on error resume or on error resume next's or on error goto 0's. When the message box comes up, hit ctrl+break to go into debug mode or if the end/debug dialog comes up click on debug. Now you will know what line the error is coming from and from where... Post it...



                          Good Luck

                          Comment

                          • QVeen72
                            Recognized Expert Top Contributor
                            • Oct 2006
                            • 1445

                            #14
                            @MA10,

                            After doing all the modifications, what error are you getting..? and What part of the code is the error pointing..?

                            Comment

                            • MA10
                              New Member
                              • May 2010
                              • 10

                              #15
                              Still at the same part...But,it's okay 'cause I've decided to use the parameter value for the view buttons since I've no much time left...And fortunately, they works well...Now, there is only one more button that I've to work on which is the 'Login' button... So do u have some examples on the coding?

                              Comment

                              Working...