473,396 Members | 2,147 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,396 software developers and data experts.

3705 "operation is not allowed when the object is open" in vb6 + ms access

Plese help in this code , i have mentioned comment where error comes

Expand|Select|Wrap|Line Numbers
  1.     For iox = nMinID To nTotID
  2.  
  3.         On Error GoTo Hell
  4.  
  5.         Call Progress(iox, nTotID)
  6.  
  7.  
  8.         con.Execute "delete from  ATACZ_Account_Data"
  9.  
  10.     'error comes in this line
  11.         Rs.Open "insert into ATACZ_Account_Data select * from ESTMT_ATACZ_Account_Data where [supress] ='F' and [ATACZ-EMAIL] <>'' and id =" & iox, con, adOpenDynamic, adLockOptimistic
  12.  
  13.         Rs.Open "select * from ATACZ_Account_Data where id =" & iox, con, adOpenDynamic, adLockOptimistic
  14.  
  15.         Set Rs.ActiveConnection = Nothing
  16.  
  17.         Counter = Counter + 1
  18.  
  19.         DoEvents
  20.  
  21.         If Counter Mod 1000 = 0 Then
  22.  
  23.             If Len(Dir("C:\PNBApplication\Temp\*.ps")) > 0 Then
  24.             'deepak Kill "C:\PNBApplication\Temp\*.ps"
  25.             End If
  26.  
  27.             If Len(Dir("C:\PNBApplication\Temp\*.csv")) > 0 Then
  28.                 Kill "C:\PNBApplication\Temp\*.csv"
  29.             End If
  30.  
  31.             If Len(Dir("C:\PNBApplication\Temp\*.pdf")) > 0 Then
  32.                 Kill "C:\PNBApplication\Temp\*.pdf"
  33.             End If
  34.  
  35.             If Len(Dir("C:\PNBApplication\Temp\out*.bat")) > 0 Then
  36.                 Kill "C:\PNBApplication\Temp\out*.bat"
  37.             End If
  38.             Shell "taskkill /F /IM acrotray.exe", vbHide
  39.  
  40.         End If
  41.  
  42.         Label8.Caption = "Current Record :" & iox
  43.         DoEvents
  44.  
  45.  
  46.         If Not Rs.EOF Then
  47.  
  48.              If Check1.Value = vbUnchecked Then
  49.             Report.DiscardSavedData
  50.             Set crpParamDefs = Report.ParameterFields
  51.             For Each crpParamDef In crpParamDefs
  52.                 With crpParamDef
  53.                     Select Case UCase(Trim(.ParameterFieldName))
  54.                         Case "ID"
  55.                         .ClearCurrentValueAndRange
  56.                         .AddCurrentValue CDbl(Rs.Fields("ID"))
  57.                      End Select
  58.                 End With
  59.             Next
  60.  
  61.             If OptNormal.Value = True Then Set CRXReport = CRXApp.OpenReport("C:\PNBApplication\Reports\Normal\PNB_EmailStatement_Normal.rpt")
  62.             If OptSilver.Value = True Then Set CRXReport = CRXApp.OpenReport("C:\PNBApplication\Reports\Silver\PNB_EmailStatement_Silver.rpt")
  63.             If OptGold.Value = True Then Set CRXReport = CRXApp.OpenReport("C:\PNBApplication\Reports\Gold\PNB_EmailStatement_Gold.rpt")
  64.             If OptCorporate.Value = True Then Set CRXReport = CRXApp.OpenReport("C:\PNBApplication\Reports\Corporate\PNB_EmailStatement_Corporate.rpt")
  65.  
  66.  
  67.             CRXReport.SelectPrinter "psscript.drv", "XeroxColor", "LPT1:"
  68.             CRXReport.PaperOrientation = crPortrait
  69.             CRXReport.PaperSize = crPaperA4
  70.             End If
  71.  
  72.             nFileName = Format(Rs("ATACZ-DATE-CURR-STMT"), "ddMMyy") & Format(Rs("id"), "000000")
  73.  
  74.             If Len(Dir("C:\PNBApplication\GeneratedFiles\" & nFileName & ".pdf")) > 0 Then
  75.  
  76.                 LogsWriter ("Already Exists " & nFileName & ".pdf")
  77.             Else
  78.  
  79.             FileCounter = FileCounter + 1
  80.  
  81.  
  82.             LogsWriter ("Statement No : " & iox & " Started.")
  83.             Filenamx2 = "C:\PNBApplication\Temp\" & Format(Rs("ATACZ-DATE-CURR-STMT"), "ddMMyy") & Format(Rs("id"), "000000")
  84.  
  85.  
  86.             If Check1.Value = vbUnchecked Then
  87.                           CRXReport.PrintOutEx False, 1, False, 1, -1, Filenamx2
  88.             End If
  89.  
  90.             nAccNo = Right(Trim(CStr(Rs("ATACZ-ACCT"))), 16)
  91.             cPwd = nAccNo
  92.  
  93.             nFileName = Format(Rs("ATACZ-DATE-CURR-STMT"), "ddMMyy") & Format(Rs("id"), "000000")
  94.             Open Text4.Text & "\MIS" & Format(Now(), "ddMMyy") & ".csv" For Append As #3
  95.             Print #3, nAccNo & "," & Rs("ATACZ-NAME-LINE-1") & "," & Rs("ATACZ-EMAIL") & "," & nFileName & ".pdf," & cPwd
  96.             Close #3
  97.  
  98.             If Check1.Value = vbUnchecked Then
  99.             Open Filenamx2 For Binary As #1
  100.             P = String(LOF(1), vbNullChar)
  101.             Get 1, , P
  102.             Close #1
  103.  
  104.             Open Filenamx2 & ".ps" For Binary As #2
  105.             Put #2, , P
  106.             Put #2, , S
  107.             Close #2
  108.  
  109.             Kill (Filenamx2)
  110.  
  111.             Open "C:\PNBApplication\Temp\out" & Rs("ID") & ".bat" For Append As #3
  112.             Print #3, "C:\gs\gs8.14\lib\ps2pdf14.bat  -sOwnerPassword#PBXkkmmd1250 -sUserPassword#" & cPwd & " C:\PNBApplication\Temp\" & nFileName & ".ps " & Text4.Text & "\" & nFileName & ".pdf"
  113.             'Print #3, "del C:\PNBApplication\Temp\" & nFileName & ".ps"
  114.             Close #3
  115.  
  116.             RetVal = Shell("C:\PNBApplication\Temp\out" & Rs("ID") & ".bat", vbHide)
  117.             Label9.Caption = "Generated Files :" & FileCounter
  118.             End If
  119.  
  120.             '-i c:\sample.pdf -w owner -u user -e 40
  121.             'RetVal = Shell("C:\Program Files\AdultPDF\PDFEncrypt\EncryptPDF -i C:\pnbstmt\" & nFileName & ".pdf  -w PBXkkmmd1250 -u " & cPwd & " -e 40", vbHide)
  122.  
  123.             LogsWriter ("Statement No :" & iox & " Completed.")
  124.             DoEvents
  125.  
  126.             End If
  127.             End If
  128.  
  129.         Rs.Close
  130.         nAccNo = ""
  131.         cPwd = ""
  132.         nFileName = ""
  133.         DoEvents
  134.         If iox > nTotID Then Exit For
  135.  
  136. Hell:
  137.        If Len(Err.Description) <> 0 Then
  138.         LogsWriter ("Error : STMT No :" & iox & Err.Description)
  139.        End If
  140.  
  141.     Next
  142.  
Sep 21 '11 #1
2 6705
Stewart Ross
2,545 Expert Mod 2GB
The error message is telling you that you are trying to open your recordset on a pass of your FOR-loop when it is already open, despite having a close statement somewhere near the end of the loop. Once a recordset is open you cannot (and should not) re-open it unless you close the recordset before trying to re-open it, at the end of each pass through the loop. You are also closing the active connection on each pass through the loop - which makes no sense to me.

My guess is that trying to open a recordset like this is unlikely to make sense - normally the recordset is opened BEFORE any loop processing takes place, and closed AFTER.

In addition, you have error processing code within the loop, titled somewhat unfortunately as 'Hell'. The structure of your code as it stands is not something I could recommend as good practice, being difficult to follow. I'd suggest you rewrite it, as even if you clear the errors it will still be a long code segment which has no comments to guide whoever is reading it about what it does.

At the very least, you will need to set a breakpoint so you can step and trace execution of your code line by line to determine why your Rs.Close statement is not being executed.

-Stewart
Sep 21 '11 #2
nico5038
3,080 Expert 2GB
I would expect a "con.execute" instead of the "rs.open", as you're using an action query to fill the table.

Nic;o)
Sep 21 '11 #3

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...
6
by: blueblueblue2005 | last post by:
here is a friend function of Class Array, which has two private data member: int size, int *ptr // Array's public member function to return size int getSize() const { return size; } friend...
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 =...
5
by: Sonasang | last post by:
Hi , I am creating a web page with ASP and Javascript.We have shared the foldres containg the code and all our team members are accessing the code. There is no problem for me when i run the...
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: Sathia1 | last post by:
Hello everyone, I am using a module in access to write a query. I first opened a connection to my database, and wrote my query in SQL in the module itself, then I have the following codes: ...
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.