my problem is i want to save a date from label in vb to field in ms access but i do not know that problem with my coding, the error appear is run-time error 91 object variable or with block variable not set, can anyone check my coding?

Dim Con As New ADODB.Connection
Dim Rs As New ADODB.Recordset

Private Sub cmdfind_Click()

Dim search As String
search = txtfind.Text

Call OpenConnection

With Rs
    .ActiveConnection = Con
    .CursorType = adOpenDynamic
    .CursorLocation = adUseClient
    .LockType = adLockOptimistic
    .Open "SELECT * FROM STUDENTS where [reg] like" & "'" & search & "'", Con, adOpenStatic, adLockOptimistic
End With

If Rs.EOF = True Or Rs.BOF = True Then
    MsgBox "PLEASE REGISTER YOUR NAME TO WARDEN"
        Else
        txtNAME = Rs.Fields("NAME")
        txtMATRIX = Rs.Fields("MATRIX NO")
        txtIC = Rs.Fields("IC NO")
        txtCONT = Rs.Fields("CONTACT NO")
        txtROOM = Rs.Fields("ROOM NO")
        lblTMEOUT.Caption = Now




End If

Set Rs = Nothing
Set Con = Nothing

cmdfind.Visible = False
txtfind.Visible = False
Label1.Visible = False
frminfo.Visible = True

End Sub

Private Sub OpenConnection()

Con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Fairus\Documents\docklet\my work\project\HOSTEL STUDENT.mdb;Persist Security Info=False"
Con.Open

End Sub


Private Sub cmdrecord_Click()
STUDENT.Recordset.Update
STUDENT.Recordset.Fields("TIME OUT") = lblTMEOUT

End Sub

What line is throwing the error?

line 52-56 . because that things i want save the date and time from label to data base

Set Rs = Nothing
Set Con = Nothing

don't set Nothing to these objects because you will use rs incmdrecord_Click() procedure.So remove these lines.

and use this :-

rs.Fields("TIME OUT") = lblTMEOUT
rs.Update
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.