Solved

run time error 3709 database connection problem

Posted on 2004-04-26
8
1,486 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Opening Remote & Local Data Connection 2 51
Excel VBA, find a string in a column, update a cell 7 67
Add and format columns in vb6 7 47
MsgBox 4 47
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

896 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now