0

I wrote code

Private Sub cmdok_Click()
Dim rs As New ADODB.Recordset
Dim strSql As String

Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.LockType = adLockOptimistic
rs.CursorType = adOpenDynamic



strSql = "SELECT * FROM tb_absensi " & _
        " WHERE nrp='" & cmbnrp & "'" & _
        " AND tanggal = " & CDate(lbltgl.Caption)

rs.Open strSql, Conn

MsgBox rs.RecordCount

Select Case cmbstatus

    Case "Masuk"
        rs.AddNew
        rs!nrp = cmbnrp
        rs!masuk = Label6.Caption
        rs!tanggal = lbltgl.Caption
        rs.Update
        rs.Open strSql, Conn


    Case "Pulang"
        rs.Open strSql, Conn
        rs!pulang = Label6.Caption
        rs.Update

End Select
Unload Me
End Sub

when I run the scrip, appear error "run-time error 3705 Operation is not allowed when the object is open"
please help me, what should I do to make it run properly

Thanks before

3
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by AndreRet
0

If you look at line 28, you should see that you're trying to open an already open recordset. You shouldn't need to do that.

What is it you wanted to happen there? Refreshing something?

0

Add the following code after your SQL string...

strSql = "SELECT * FROM tb_absensi " & _
        " WHERE nrp='" & cmbnrp & "'" & _
        " AND tanggal = " & CDate(lbltgl.Caption)

If rs.State = 1 then
    rs.Close
End If

rs.Open strSql, Conn

You then opened your recordset, let it give you a test message and then you started a select case statement where you want to open it again. You need to close the recordset first before you can open it again...

rs.Close
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.