I got a runtime error 3705 "Operation is not allowed when the object is open". When I click debug, it highlights the connection object I made in the module. I have a form named frmUser. When I click mnu_User from the mdiForm, I got a runtime error 3705, but when I set the frmUser as the Start-up object in the project properties, I didn't get any error.. The error only occurs when I call the frmUser from the mdiForm.
Here is the code for the connection:
Public conn As New ADODB.Connection
Public Sub S_OPEN_DB()
conn.ConnectionString = _ ' It
"Provider = msdasql.1;" & _ ' Highlights
"data source = kath_cn" ' Here
conn.Open
End Sub
Here is the code for the frmUser:
Private Sub Form_Load()
S_OPEN_DB
S_LOAD_flxUser
End Sub
Public Sub S_LOAD_flxUser()
Dim rsLoad As ADODB.Recordset
Dim a As Integer
With flxUser
.Clear
.Rows = 24
.Cols = 6
.ColWidth(0) = 300
.ColWidth(1) = 1000: .TextMatrix(0, 1) = "User ID"
.ColWidth(2) = 2000: .TextMatrix(0, 2) = "User Type"
.ColWidth(3) = 2000: .TextMatrix(0, 3) = "Username"
.ColWidth(4) = 2000: .TextMatrix(0, 4) = "Password"
.ColWidth(5) = 4000: .TextMatrix(0, 5) = "Name"
End With
a = 1
Set rsLoad = New ADODB.Recordset
rsLoad.Open "select * from user_tab order by UserID", conn, adOpenStatic, adLockOptimistic
With rsLoad
Do While .EOF = False
flxUser.TextMatrix(a, 1) = !UserID
flxUser.TextMatrix(a, 2) = !UserType
flxUser.TextMatrix(a, 3) = !UserName
flxUser.TextMatrix(a, 4) = !Password
flxUser.TextMatrix(a, 5) = !UserFullName
.MoveNext
If .EOF = False Then
flxUser.Rows = flxUser.Rows + 1
a = a + 1
End If
Loop
.Close
End With
End Sub