Hi,

Can anyone please help me with my command button.
What it's suppose to do is if vbYes is chosen, then it will update a Field (fieldname "Approved") = True.
If vbNo then the updates will be deleted.

This command Save button is in a form which calls on a data table called TblCover to update the field.

When I run this code, it gives me the error "RUNTIME ERROR 91 - object variable or with block variable not set" amd it highlights the line " .Open ..."

Can anyone please help me?
==============================================

Private Sub cmdSave_Click()
  
    Response = MsgBox("Has this been Signed and Approved?", vbYesNo + vbCritical)
    
    If Response = vbYes Then
    Set ActiveConnection = TblCover
    With rst
       .Open "TblCover", cnn, adOpenDynamic, adLockOptimistic
       .Fields("Approved").Value = True
       .Update
       DoCmd.Save acForm, "Cover"
    End With
    
    End If
    
    If Response = vbNo Then
        strText = MsgBox("You need to get Manager signature and Approval", vbCritical)
   With rst
      .Delete (adAffectCurrent)
      .Close
    End With
    Set myRecordset = Nothing
    Set conn = Nothing
    End If

End Sub

i think wherever u got that script is bs

Finally worked this out with some help...
Have to be careful with the use of DAO and ADO. THis is where I got confused most with which language to use...
--------------------------------------------------------------

Private Sub cmdSave_Click()

    Dim Response As VbMsgBoxResult
    Dim TblCoverId As Integer
    Dim TblCoverRS As DAO.Recordset
    TblCoverId = ID
    
    Response = MsgBox("Has this been Signed and Approved?", vbYesNo + vbCritical)
    If Response = vbYes Then
        Set TblCoverRS = CurrentDb.OpenRecordset("Select * from TblCover where ID = " & CStr(TblCoverId))
        TblCoverRS.OpenRecordset
        TblCoverRS.Edit
        TblCoverRS!Approved = True
        TblCoverRS.Update
        TblCoverRS.Close
        
    Else
        Set TblCoverRS = CurrentDb.OpenRecordset("Select * from TblCover where ID = " & CStr(TblCoverId))
        TblCoverRS.OpenRecordset
        TblCoverRS.Delete
    End If
    
      Set TblCoverRS = Nothing

End Sub

that script makes no sense what language is it really?

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.