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

Recommended Answers

All 2 Replies

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?

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.