Print the newly added record to a report

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AngelaZeb
    New Member
    • Mar 2020
    • 1

    Print the newly added record to a report

    I have a MS Access unbound form that supposed to collect data from a user then add the new record to a table (tblResearchReq ) then print preview the newly added record in a report after the user clicks the submit button. I use DAO to add the new record and the rst.Bookmark = rst.LastModifie d to position the recordset to the last modified record. The record gets added to the table but object variable is not being set. Getting error "object Variable not set from the rst.Bookmark = rst.LastModifie d. Code is as follows:
    Code:
    Private Sub cmdSubmit_Click()
    On Error GoTo Err_cmdSubmit_Click
    
    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    Dim StrWhere As String
    
    Set rst = CurrentDb.OpenRecordset(Name:="tblResearchReq", Type:=RecordsetTypeEnum.dbOpenDynaset)
    
        If IsNull(Me.cboResearchCat) Or Me.cboResearchCat = "" Then
            MsgBox "Request Category is required", vbOKOnly, "Research Request"
            Me.cboResearchCat.SetFocus
            Exit Sub
        End If
        If IsNull(Me.ChkAmt) Then
            MsgBox "Check Amount is required", vbOKOnly, "Research Request"
            Me.ChkAmt.SetFocus
            Exit Sub
        End If
        If IsNull(Me.ItemNo) Then
            MsgBox "Item Number is required", vbOKOnly, "Research Request"
            Me.ItemNo.SetFocus
            Exit Sub
        End If
        If IsNull(Me.Payer) Or Payer = "" Then
            MsgBox "Payer is required", vbOKOnly, "Research Request"
            Me.Payer.SetFocus
            Exit Sub
        End If
        
        With rst
        .AddNew
            rst!RecID = Me.RecID
            rst!BatchDate = Me.BatchDate
            rst!DepositType = Me.DepositType
            rst!Requestor = Me.Requestor
            rst!ResearchCat = Me.cboResearchCat
            rst!RequestType = Me.cboRequestType
            rst!ChkAmt = Me.ChkAmt
            rst!ItemNo = Me.ItemNo
            rst!Payer = Me.Payer
            rst!Comments = Me.Comments
            rst!Foundations = Me.chkFoundations
            rst!ePremis = Me.chkEPremis
            rst!HC = Me.chkHC
            rst!HealthLogic = Me.chkHealthLogic
            rst!Other = Me.chkOther
            rst!CashPro = Me.chkCashPro
            rst!ResReqTime = Now()
        .Update
    '   .Bookmark = .LastModified
        End With
    'rst.Bookmark = rst.LastModified
    
    StrWhere = "ResReqID = " & Me.ResReqID
    DoCmd.OpenReport "rpt911InvBatch", acViewPreview, , StrWhere
    
    rst.Close
    db.Close
      
    Exit_cmdSubmit_Click:
        Exit Sub
    
    Err_cmdSubmit_Click:
        MsgBox Err.Description
        Resume Exit_cmdSubmit_Click
    End Sub
    The front-end links to tables in an MS Access Back-end. I've tried variations of setting up the recordset and googled everything I could think of to find a resolution and now just seem to be spinning my wheels. I hope I am being specific and provided the appropriate amount information. Thanks ahead of time for any assistance you can provide.
    Last edited by twinnyfo; Mar 30 '20, 11:09 AM. Reason: added code tags
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Not all Recordsets support Bookmarks and this can easily be determined by:
    Code:
    With rst
      .AddNew
        !RecID = Me.RecID
        !BatchDate = Me.BatchDate
        !DepositType = Me.DepositType
        !Requestor = Me.Requestor
        !ResearchCat = Me.cboResearchCat
        !RequestType = Me.cboRequestType
        !ChkAmt = Me.ChkAmt
        !ItemNo = Me.ItemNo
        !Payer = Me.Payer
        !Comments = Me.Comments
        !Foundations = Me.chkFoundations
        !ePremis = Me.chkEPremis
        !HC = Me.chkHC
        !HealthLogic = Me.chkHealthLogic
        !Other = Me.chkOther
        !CashPro = Me.chkCashPro
        !ResReqTime = Now()
      .Update
    End With
    
    If rst.Bookmarkable Then
      rst.Bookmark = rst.LastModified
    End If

    Comment

    Working...