operation is not allowed when the object is open in vb6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Proggy
    New Member
    • Oct 2014
    • 13

    operation is not allowed when the object is open in vb6

    I keep getting an error operation is not allowed when the object is open in this code. anybody can help me in this?
    can you please check m code?
    tnx.
    your help is greatly appreciated.

    Code:
    Private Sub cmdPrint_Click()
    Set rs = Adodc1.Recordset
    rs.Open "select * from tblborrower where AccessionNumber = " & CInt(txtAccessionNumber.Text) & " ", con, adOpenStatic, adLockOptimistic, adCmdText
       
       
     
      
           
          
           With DataReport3
           Set DataReport3.DataSource = rs
           .Sections("Section1").Controls("txtType").DataField = "status"
           .Sections("Section1").Controls("txtSection").DataField = "section"
           .Sections("Section1").Controls("txtborrower").DataField = "Borrower"
           .Sections("Section1").Controls("txtAccessionNumber").DataField = "AccessionNumber"
            .Sections("Section1").Controls("txtBooktitle").DataField = "BookTitle"
            .Sections("Section1").Controls("txtbooknumber").DataField = "BookNumber"
            .Sections("Section1").Controls("txtDB").DataField = "DateBorrowed"
            .Sections("Section1").Controls("txtCategory").DataField = "Category"
            .Sections("Section1").Controls("txtDR").DataField = "DateReturned"
            .Sections("Section1").Controls("txtremarks").DataField = "remarks"
            .Sections("Section1").Controls("txtcondition").DataField = "Condition"
            .Sections("Section1").Controls("txtdaysborrow").DataField = "department"
            .Sections("Section1").Controls("txtoverdue").DataField = "overduedays"
            .Sections("Section1").Controls("txtdays").DataField = "howmanydays"
            .Sections("Section1").Controls("txtfines").DataField = "fines"
        
            
         
           .Show
       End With
       
    
    End Sub
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3653

    #2
    Proggy,

    At which line of code are you getting the error? You should also make sure you use the "Option Explicit" declaration at the beginning of your code.

    Also, in your code, based on what you have posted, I see no need to use any recordset, since you are simply assigning text values to your text boxes. Maybe I am missing something--or this is not what you are trying to do....

    Comment

    • Proggy
      New Member
      • Oct 2014
      • 13

      #3
      on this line : rs.Open "select * from tblborrower where AccessionNumber = " & CInt(txtAccessi onNumber.Text) & " ", con, adOpenStatic, adLockOptimisti c, adCmdText.

      i did removing the recordset but its not really working.

      Comment

      • Proggy
        New Member
        • Oct 2014
        • 13

        #4
        what i am trying to do is to print a single record. but this error keeps on showing.

        Comment

        • twinnyfo
          Recognized Expert Moderator Specialist
          • Nov 2011
          • 3653

          #5
          Proggy,

          the biggest problem I see with trying to troubleshoot this code is that you have not declared any of your variables (thus my advice in Post #2 to add "Option Explicit" to the top of your module. Once you do this, step through the debugger and fix any errors that the VBA Editor finds first.

          Again, it begs the question why you are trying to do what you are trying to do in the way the you are trying to do it.

          If the Form has tblborrower as its Record Source (which I think in this case, it should), just filter the Form by the selected Accession Number:

          Code:
          Me.Form.Filter = "AccessionNumber = " & _
              CInt(txtAccessionNumber.Text)
          Me.Form.FilterOn = True
          Additionally, if your text box (txtAccessionNu mber) holds a number, there is no need to use either the CInt() Function or the ".Text" property.

          Unless I am missing something obvious, your code seems to over complexify a very simple process. But, that is what this forum is here for, to help users improve their coding skills.

          Comment

          • twinnyfo
            Recognized Expert Moderator Specialist
            • Nov 2011
            • 3653

            #6
            I am glad that I could be of some assistance with this problem.

            Comment

            Working...