0

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
2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by SKANK!!!!!
0

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
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.