Solved

run time error 3709 database connection problem

Posted on 2004-04-26
8
1,493 Views
Last Modified: 2013-12-25
hi,
im recieving the run time error 3709: the connection cannot be used to perform this operation. It is either closed or invalid in this context.


My program consists of a MainMenu form (which is the startup form) and a Customer Form (which is linked to the database). When i first click on the main menu form to access the Customer Form everything runs fine with the database connection... though when i click to go back to the mainmenu frm and then try to go back into the Customer Form again... the database connection closes for some reason and the run time error comes up... the following code is highlighted when i debug.

mrsCustomers.Open pstCustomersSQL, gcnCoastandCountry, adOpenStatic, adLockOptimistic, adCmdText

here is the rest of my code

Module:
Option Explicit
'**Declare a New ADODB connection object variable
Public gcnCoastandCountry As New ADODB.Connection

Sub Main()
If Left(App.Path, 2) <> "\\" Then
    ChDrive App.Path
End If
ChDir App.Path
'**Open the connection to the database
gcnCoastandCountry.Open "Provider = Microsoft.jet.OLEDB.4.0; Data Source = CoastandCountry.mdb"
frmMainMenu.Show 1
End Sub

Sub CloseConnection()
gcnCoastandCountry.Close
Set gcnCoastandCountry = Nothing
End Sub

here is the Code on the MainMenu form:

Private Sub cmdCustomers_Click()
frmcustomers.Show 1
End Sub

here is the code on the Customer Form to go back the Main Menu form:

Private Sub cmdmainmenu_Click()
'**Close the recordset and database before exiting
mrsCustomers.Close
Set mrsCustomers = Nothing
Call CloseConnection
Unload frmcustomers
End Sub

Thanks,
Spiz
0
Comment
Question by:igotnosmoke
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 10916982
In what event is this ?
mrsCustomers.Open pstCustomersSQL, gcnCoastandCountry, adOpenStatic, adLockOptimistic, adCmdText
0
 

Author Comment

by:igotnosmoke
ID: 10917013
its in the Customer Form... Form Load
here the whole code

Private Sub Form_Load()
Dim pstCustomersSQL As String
frmcustomers.WindowState = 2
Call SetInactiveTextBoxes
pstCustomersSQL = "SELECT * FROM tblCustomers ORDER BY CustomerNumber"
mrsCustomers.Open pstCustomersSQL, gcnCoastandCountry, adOpenStatic, adLockOptimistic, adCmdText
If mrsCustomers.RecordCount > 0 Then
    Call DisplayData
Else
    'Call ClearData
End If
End Sub
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 10917037
Where did you declare mrsCustomers ?

Private Sub Form_Load()
on error goto LoadError
   Dim pstCustomersSQL As String
   dim mrsCustomers as ADODB.Recordset
   frmcustomers.WindowState = 2
   Call SetInactiveTextBoxes
   pstCustomersSQL = "SELECT * FROM tblCustomers ORDER BY CustomerNumber"
   mrsCustomers.Open pstCustomersSQL, gcnCoastandCountry, adOpenStatic, adLockOptimistic, adCmdText
   If mrsCustomers.RecordCount > 0 Then
       Call DisplayData
   Else
       'Call ClearData
   End If
   exit sub
LoadError:
   msgbox err.number & " " & err.description
End Sub

0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:igotnosmoke
ID: 10917369
i declared mrsCustomers in the customers form

Option Explicit
'**Declare a modlule-level variable for the recordst which is to be used by more
'**than one procedure in the form module.
Private mrsCustomers As New ADODB.Recordset
Private mcocontrol As Control
Private mstmode As String
Private mstCustomerNumber As String
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 10917405
You close your complete connection in your child-form

Private Sub cmdmainmenu_Click()
'**Close the recordset and database before exiting
mrsCustomers.Close
Set mrsCustomers = Nothing
'Call CloseConnection
Unload frmcustomers
End Sub

Remove the call CloseConnection !
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 10917686
0
 

Author Comment

by:igotnosmoke
ID: 10917936
Hey sorry about that i didnt know that you couldnt post more then 500... respond to this ill give u the 500
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 10918857
No problem at all. Glad I could help you out with your problems.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month8 days, 1 hour left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question