473,322 Members | 1,755 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,322 software developers and data experts.

Error on Execute in access application

Hi
This code is part of an application currently running in production which I must perform maintenance on. On my PC it throwing an error after the execute command. My Odbc connection is working fine and connecting to the db.
The error message says that "The connection cannot be used to perform this type of operation it is either closed or can not be used in this context"
Code must be ok so whats amiss

Dim cmdInv As ADODB.Command
Dim rstInv As ADODB.Recordset
Dim fOpen As Boolean

On Error GoTo ErrHandler

'fOpen = OpenInvCSConnection

Set cmdInv = New ADODB.Command
Set rstInv = New ADODB.Recordset

Set cmdInv.ActiveConnection = cnnSCDB
If OpenSCDBConnection Then

End If
With cmdInv
.CommandType = adCmdText
.CommandText = "Select * From tblInvoiceNos where RecID = " & 1
End With

Set rstInv = cmdInv.Execute
rstInv.MoveFirst

Select Case InvType
Case "R"
GetNextInvNo = rstInv!RentalInvNos
'Case "M"
' GetNextInvNo = rstInv!MaintInvNos
'Case "S"
' GetNextInvNo = rstInv!ServiceInvNos
End Select

rstInv.Close

ExitHere:
Exit Function

ErrHandler:
Call DispErrObj(Err, name & " GetNxtInvNos")

Thanks in anticipation!!
Nov 20 '06 #1
7 1401
MMcCarthy
14,534 Expert Mod 8TB
I just don't think you can do this ... you've already set the resInv anyway.

Expand|Select|Wrap|Line Numbers
  1. Set rstInv = cmdInv.Execute
try this instead

Expand|Select|Wrap|Line Numbers
  1. rstInv.Open cmdInv.Execute
Nov 21 '06 #2
Killer42
8,435 Expert 8TB
I just don't think you can do this ...
Do you think maybe it's due to the poster running a different version of Access to whoever developed the code? I know I've been tripped up a few times by version changes in database access (from VB in my case though, not Access).
Nov 21 '06 #3
MMcCarthy
14,534 Expert Mod 8TB
Do you think maybe it's due to the poster running a different version of Access to whoever developed the code? I know I've been tripped up a few times by version changes in database access (from VB in my case though, not Access).
ADO's not my area of expertise but I think you have to open a recordset and I can't see any code doing that.

Version changes are a problem at times but usually because of library and functional changes.
Nov 21 '06 #4
willakawill
1,646 1GB
Dim cmdInv As ADODB.Command
Dim rstInv As ADODB.Recordset
Dim fOpen As Boolean

On Error GoTo ErrHandler

'fOpen = OpenInvCSConnection

Set cmdInv = New ADODB.Command
Set rstInv = New ADODB.Recordset

Set cmdInv.ActiveConnection = cnnSCDB
If OpenSCDBConnection Then

End If
With cmdInv
.CommandType = adCmdText
.CommandText = "Select * From tblInvoiceNos where RecID = " & 1
End With

Set rstInv = cmdInv.Execute
Hi.
2 things here. there is no need to initialize the recordset with New (not a major problem, just a waste of code) and there is no indication here that the connection object cnnSCDB is open. This second item is likely to be causing the error. Your code is fine, just can't see where the connection is opened.
Nov 21 '06 #5
Killer42
8,435 Expert 8TB
ADO's not my area of expertise but I think you have to open a recordset and I can't see any code doing that.
Version changes are a problem at times but usually because of library and functional changes.
Well, it's just that the OP did say it was known-working Production code, which then wouldn't run on his/her PC.
Nov 21 '06 #6
willakawill
1,646 1GB
Well, it's just that the OP did say it was known-working Production code, which then wouldn't run on his/her PC.
Which would indicate that the connection object is not working
Nov 22 '06 #7
Killer42
8,435 Expert 8TB
Which would indicate that the connection object is not working
Sounds reasonable.

I was just making the point that if the code does work on a bunch of PCs but not on one particular one, then it seems unlikey to be an error in the code.
Nov 22 '06 #8

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

Similar topics

3
by: Nathan Bloomfield | last post by:
Hi there, I am having difficulty with a piece of code which would work wonders for my application if only the error trapping worked properly. Basically, it works as follows: - adds records...
6
by: AlanS | last post by:
I have used Visual Studio for about 8 months. I have developed some ASP solutions. I had to get on with some other things and have not worked with ASP.NET for a couple months. In the meantime, I...
5
by: Bruce Schechter | last post by:
I just started to develop an ASP.NET application in vs.net 2003 . But each time I try to execute the application (which is basically empty so far), I get a dialog box titled "Microsoft Development...
10
by: Shawn | last post by:
JIT Debugging failed with the following error: Access is denied. JIT Debugging was initiated by the following account 'PLISKEN\ASPNET' I get this messag in a dialog window when I try to open an...
12
by: Griff | last post by:
I have a two tier system. I've created a COM+ package on the data tier (Win2003) and exported it as a COM+proxy (v 1.0 compliant) and installed this onto a Win2000 web application. I've...
23
by: deathtospam | last post by:
A day or two ago, I wrote a quick ASPX page with a CS codebehind using Visual Studio .NET 2005 -- it worked, I saved it and closed the project. Today, I came back to the project, reopened the...
5
by: JC | last post by:
Hi, I have a simple web application and It works well in my local computer.. When i upload it to my web server i get this error: Server Error in '/' Application....
6
by: =?Utf-8?B?RGF2ZQ==?= | last post by:
I'm running VS 2003/ASP.NET 1.1.4322.0 on XP SP2 All of a sudden I started to getting... "Error while trying to run project: Unable to start debugging on the web server. Server side-error...
17
by: =?Utf-8?B?RGF2ZQ==?= | last post by:
I have set up a virtual directory using IIS. Whenever, I load a web page of type .htm, I have no problem. Whenever I run a .aspx page I get the statement below. I am running on XP Pro, both...
5
by: prakashwadhwani | last post by:
The Delete Event/Proc & "Save_Fields_In_Form_Header" Event/Proc in my form were working perfectly. However, after I added a call to the "Save_Fields_In_Form_Header" Event/Proc in the...
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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.