Solved

run time error 3709 database connection problem

Posted on 2004-04-26
8
1,490 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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 I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

763 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