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