473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.LastModified 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.LastModified. Code is as follows:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSubmit_Click()
  2. On Error GoTo Err_cmdSubmit_Click
  3.  
  4. Dim db As DAO.Database
  5. Dim rst As DAO.Recordset
  6. Dim StrWhere As String
  7.  
  8. Set rst = CurrentDb.OpenRecordset(Name:="tblResearchReq", Type:=RecordsetTypeEnum.dbOpenDynaset)
  9.  
  10.     If IsNull(Me.cboResearchCat) Or Me.cboResearchCat = "" Then
  11.         MsgBox "Request Category is required", vbOKOnly, "Research Request"
  12.         Me.cboResearchCat.SetFocus
  13.         Exit Sub
  14.     End If
  15.     If IsNull(Me.ChkAmt) Then
  16.         MsgBox "Check Amount is required", vbOKOnly, "Research Request"
  17.         Me.ChkAmt.SetFocus
  18.         Exit Sub
  19.     End If
  20.     If IsNull(Me.ItemNo) Then
  21.         MsgBox "Item Number is required", vbOKOnly, "Research Request"
  22.         Me.ItemNo.SetFocus
  23.         Exit Sub
  24.     End If
  25.     If IsNull(Me.Payer) Or Payer = "" Then
  26.         MsgBox "Payer is required", vbOKOnly, "Research Request"
  27.         Me.Payer.SetFocus
  28.         Exit Sub
  29.     End If
  30.  
  31.     With rst
  32.     .AddNew
  33.         rst!RecID = Me.RecID
  34.         rst!BatchDate = Me.BatchDate
  35.         rst!DepositType = Me.DepositType
  36.         rst!Requestor = Me.Requestor
  37.         rst!ResearchCat = Me.cboResearchCat
  38.         rst!RequestType = Me.cboRequestType
  39.         rst!ChkAmt = Me.ChkAmt
  40.         rst!ItemNo = Me.ItemNo
  41.         rst!Payer = Me.Payer
  42.         rst!Comments = Me.Comments
  43.         rst!Foundations = Me.chkFoundations
  44.         rst!ePremis = Me.chkEPremis
  45.         rst!HC = Me.chkHC
  46.         rst!HealthLogic = Me.chkHealthLogic
  47.         rst!Other = Me.chkOther
  48.         rst!CashPro = Me.chkCashPro
  49.         rst!ResReqTime = Now()
  50.     .Update
  51. '   .Bookmark = .LastModified
  52.     End With
  53. 'rst.Bookmark = rst.LastModified
  54.  
  55. StrWhere = "ResReqID = " & Me.ResReqID
  56. DoCmd.OpenReport "rpt911InvBatch", acViewPreview, , StrWhere
  57.  
  58. rst.Close
  59. db.Close
  60.  
  61. Exit_cmdSubmit_Click:
  62.     Exit Sub
  63.  
  64. Err_cmdSubmit_Click:
  65.     MsgBox Err.Description
  66.     Resume Exit_cmdSubmit_Click
  67. 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.
Mar 29 '20 #1
1 1164
ADezii
8,834 Expert 8TB
Not all Recordsets support Bookmarks and this can easily be determined by:
Expand|Select|Wrap|Line Numbers
  1. With rst
  2.   .AddNew
  3.     !RecID = Me.RecID
  4.     !BatchDate = Me.BatchDate
  5.     !DepositType = Me.DepositType
  6.     !Requestor = Me.Requestor
  7.     !ResearchCat = Me.cboResearchCat
  8.     !RequestType = Me.cboRequestType
  9.     !ChkAmt = Me.ChkAmt
  10.     !ItemNo = Me.ItemNo
  11.     !Payer = Me.Payer
  12.     !Comments = Me.Comments
  13.     !Foundations = Me.chkFoundations
  14.     !ePremis = Me.chkEPremis
  15.     !HC = Me.chkHC
  16.     !HealthLogic = Me.chkHealthLogic
  17.     !Other = Me.chkOther
  18.     !CashPro = Me.chkCashPro
  19.     !ResReqTime = Now()
  20.   .Update
  21. End With
  22.  
  23. If rst.Bookmarkable Then
  24.   rst.Bookmark = rst.LastModified
  25. End If
Mar 29 '20 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Tony Stoker | last post by:
I have a .Net web app that adds a record to a SQL database. After the user adds their record I want to have a link that will link them to their new record! The recordID is a AutoNumber in the...
2
by: Paul Mendez | last post by:
I have a form that consists of 150 records and is still growing. there are times when I want to print a certain record of the form, say record 12. I go to file --> print and choose the page number...
1
by: C CORDON | last post by:
How can I get the ID (in a autonumber field) for the last added record in access? TIA!
3
by: Kaur | last post by:
Hi, I would appriceate any help to correct the code error that I am getting for the onclick event of a cmd button. I have two forms. Main Form "frmQuestion" and form 2 "SfrmQuestion"....
2
by: Kaur | last post by:
Hi, I am working in MS Access 2000 and have created two forms. Form 1 is called frmParent (which has a subform called SfrmChild). FrmParent has a list box that lists all the Last Names of...
0
by: Sooraj | last post by:
Hi all I am using vb.net 2002. To add records to grid, I click on button and display modal form with various text boxes. f.showdialog() When I save the record (by selecting MAXID from table)...
9
by: =?Utf-8?B?UHJhdmlu?= | last post by:
We are using .net Framework 1.1 We are having one page on which we are using this Grid component. From this page we open a popup for adding new record as well as for editing an existing record...
2
nev
by: nev | last post by:
i place values in a new row programatically. it has an auto-increment column. after adding the entries i do... bindingsource.endedit() tableadapter.update(dataset.datatable) the saving process...
21
sueb
by: sueb | last post by:
In my IURs database (ADezii, you probably still have a good back end for this), I don't want my users to be able to change the Chart Number field, but I do want them to be able to add new ones. (In...
1
by: amirshahas77 | last post by:
I am adding new record and after saving i want it to be shown in the datagrid control.So i am writing "Adodc1.refresh" code in save button.But its not showing record in the grid although it is saving...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.