Help... Error run "3705"; Operation not allowed, object is open??

Posted on 2003-02-20
Medium Priority
Last Modified: 2008-01-09
i am programming a system for a clinic, with a dbase in Access.. the problem is that; i always get this error "operation is not allowed object is open"...; and when i press debug, it always go to the module; where i coonect access and vb..

can anyone take a look/check, to what i did wrong?? and what can i do to solve this error..

i would appreciate all the help/ suggestions.. thank u very much..

this is my code for LOGinform:

Option Explicit
Private rsSearch As New ADODB.Recordset


Private Sub cmdCancel_Click()
  MsgBox "Unable to Log In", vbOKOnly, "GoodBye"
  Unload Me
End Sub


Private Sub cmdEnter_Click()

Dim intSwitch As Integer
Dim i As Integer

rsSearch.Open "SELECT * FROM Login", CN, adOpenStatic, adLockPessimistic

    ' checks the fields of Username Input
    If txtUserName.Text = "" Then
        MsgBox "Incomplete Information", vbExclamation + vbOKOnly
        If Not rsSearch.EOF Then                                        ' searches TAlbe login until end of file
            For i = 1 To rsSearch.RecordCount                           ' loop searches for match Username and for moving the pointer
                If rsSearch("UserName").Value = txtUserName.Text Then
                      If rsSearch!Password = txtPassword.Text Then      ' checks if the inputed passwrod is correct corresponding with the username
                        Call Switch2
                        MsgBox "Invalid Password", vbCritical, vbOKOnly
                      End If
                intSwitch = 1                                           ' a flag varible; 1 = true; 0 = false
                End If
            Next i
        End If

        If intSwitch = 0 Then                                           ' didnt found a matched user
             MsgBox "User dosen't Exist!", vbCritical + vbOKOnly
             txtUserName.Text = ""
             txtPassword.Text = ""
        End If
    End If
 Set rsSearch = Nothing

' d code; when added = error 3705

rsSearch.Open "SELECT * FROM LoginTime", CN, adOpenStatic, adLockPessimistic
    rsSearch!UserName = txtUserName.Text
  rsSearch!DateLogin = Format(Date, "mm-dd-yyyy")
 rsSearch!TimeLogin = Time
Set rsSearch = Nothing

End Sub

Private Sub Form_Load()

'calls for modele (connection.bas)= conects access with vb..
End Sub


' function for calling other forms
'+ =============================

Public Sub Switch2()

    MsgBox "Welcome!", vbOKOnly, "Welcome"
        Unload Me
    End Sub


'codes in connection.bas

Option Explicit

Public CN As New ADODB.Connection
Public cnProvider As String

Public Function LoadConnection()

    cnProvider = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\CMS\dbase\medicalrecords.mdb;Persist Security Info=False"
    CN.Open cnProvider
End Function

Question by:mauve928
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
LVL 53

Expert Comment

ID: 7987557
Try this:
Set rsSearch = Nothing

set rsseach = new recordset
rsSearch.Open "SELECT * FROM LoginTime", CN, adOpenStatic, adLockPessimistic
LVL 44

Accepted Solution

Arthur_Wood earned 75 total points
ID: 7987759
if the highlighter line, when you get to DEBUG mode is:

CN.Open cnProvider

then the connection is already open and cannot be opened AGAIN.

there are two possible corrections, if that is the source of the error.


Public Function LoadConnection()

   cnProvider = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\CMS\dbase\medicalrecords.mdb;Persist Security Info=False"
   if CN.State = 0  then ' Closed
      CN.Open cnProvider
   end if
End Function



Public Function LoadConnection()

   cnProvider = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\CMS\dbase\medicalrecords.mdb;Persist Security Info=False"
   Set CN = New ADODB.Connection  ' create a New Connection object
   CN.Open cnProvider
End Function

My choice would be Option 1) (if that procedure is in fact the source of the error message)


Author Comment

ID: 7999057
Thank you, everyone.. for the help and suggestions.. :)

i already got rid of that error.. thank you, Arthur wood..

anyway, thank to the both of u..

till next time

mauve :)


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

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…
Suggested Courses

764 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