Solved

run time error 3709 database connection problem

Posted on 2004-04-26
8
1,487 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
  • 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

786 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