473,326 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

operation is not allowed when the object is open in vb6

13
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.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdPrint_Click()
  2. Set rs = Adodc1.Recordset
  3. rs.Open "select * from tblborrower where AccessionNumber = " & CInt(txtAccessionNumber.Text) & " ", con, adOpenStatic, adLockOptimistic, adCmdText
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.        With DataReport3
  11.        Set DataReport3.DataSource = rs
  12.        .Sections("Section1").Controls("txtType").DataField = "status"
  13.        .Sections("Section1").Controls("txtSection").DataField = "section"
  14.        .Sections("Section1").Controls("txtborrower").DataField = "Borrower"
  15.        .Sections("Section1").Controls("txtAccessionNumber").DataField = "AccessionNumber"
  16.         .Sections("Section1").Controls("txtBooktitle").DataField = "BookTitle"
  17.         .Sections("Section1").Controls("txtbooknumber").DataField = "BookNumber"
  18.         .Sections("Section1").Controls("txtDB").DataField = "DateBorrowed"
  19.         .Sections("Section1").Controls("txtCategory").DataField = "Category"
  20.         .Sections("Section1").Controls("txtDR").DataField = "DateReturned"
  21.         .Sections("Section1").Controls("txtremarks").DataField = "remarks"
  22.         .Sections("Section1").Controls("txtcondition").DataField = "Condition"
  23.         .Sections("Section1").Controls("txtdaysborrow").DataField = "department"
  24.         .Sections("Section1").Controls("txtoverdue").DataField = "overduedays"
  25.         .Sections("Section1").Controls("txtdays").DataField = "howmanydays"
  26.         .Sections("Section1").Controls("txtfines").DataField = "fines"
  27.  
  28.  
  29.  
  30.        .Show
  31.    End With
  32.  
  33.  
  34. End Sub
Nov 4 '14 #1

✓ answered by twinnyfo

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:

Expand|Select|Wrap|Line Numbers
  1. Me.Form.Filter = "AccessionNumber = " & _
  2.     CInt(txtAccessionNumber.Text)
  3. Me.Form.FilterOn = True
Additionally, if your text box (txtAccessionNumber) 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.

5 13956
twinnyfo
3,653 Expert Mod 2GB
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....
Nov 4 '14 #2
Proggy
13
on this line : rs.Open "select * from tblborrower where AccessionNumber = " & CInt(txtAccessionNumber.Text) & " ", con, adOpenStatic, adLockOptimistic, adCmdText.

i did removing the recordset but its not really working.
Nov 5 '14 #3
Proggy
13
what i am trying to do is to print a single record. but this error keeps on showing.
Nov 5 '14 #4
twinnyfo
3,653 Expert Mod 2GB
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:

Expand|Select|Wrap|Line Numbers
  1. Me.Form.Filter = "AccessionNumber = " & _
  2.     CInt(txtAccessionNumber.Text)
  3. Me.Form.FilterOn = True
Additionally, if your text box (txtAccessionNumber) 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.
Nov 5 '14 #5
twinnyfo
3,653 Expert Mod 2GB
I am glad that I could be of some assistance with this problem.
Mar 12 '15 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Matthew Louden | last post by:
The following ASP code yields the following error, but actually the new record is stored in database. The same error happens when the application deletes a record, such as sqlStmt ="delete from...
1
by: cliverama | last post by:
help! fried brains.... asp calling a sqlserver7 stored proc which dynamically builds a sqlstatement & passes it to sp_executesql asp page gives the operation not allowed when object is closed...
2
by: Arpan | last post by:
An ASP application updates a SQL Server database table after a Form is submitted after which the user is directed to another page that should display the updated records. If the code is ...
1
by: amitbadgi | last post by:
Hello guys I am getting this error while converting an asp applicayion to asp.net Exception Details: System.Runtime.InteropServices.COMException: Operation is not allowed when the object is...
1
by: Matt | last post by:
Got this problem that killing me...what am i doing wrong with this old dll. When i call the function from asp i get "Operation is not allowed when object is closed" any clue will be...
1
by: jigu | last post by:
<html> <head><title>testing connection asp to mdb</title></head> <body> <% dim sql_insert,sSQL src = "C:\websites1\yourdominname\mydatabase.mdb" sConnStr =...
7
vikas1111
by: vikas1111 | last post by:
Hi All.... I have created a form in which i call other forms from the main form .. When i click a perticular botton twice there is an error .. Can anyone help me to solve my problem.. The error...
1
by: sailoosha | last post by:
Hi, I am getting an error "operation not allowed when object is closed" when executing the following code. I am getting the runtime error at While Recordset.EOF <> True I am not sure where the...
2
by: vasavivenu | last post by:
Hi, My code is ElseIf pref = "Delete" Then If r.STATE = 1 Then r.Close r.Open "delete from visitors where ID=" & Val(fg.TextMatrix(fg.row, 0)), dbcon, adOpenKeyset, adLockOptimistic...
2
by: kenneth03 | last post by:
hi can you help me dubug this error it says 'operation not allowed when object is closed here is the code Private Sub Command2_Click() ch = "0" With rsStock
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.