Discussion Locked

MS Access - Tentative Append Record

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I can't get a form to print a report with the latest data entered in a record.

I've create a form for data entry. When the user clicks on the "Add Record" button, they should be able to add the information; i.e. name, location, dept., phone, etc. Then, there's a Print button that the user should be able to click and print the current record in a report based on the data just entered.

Somehow, I believe it's related to the "Tentative Append Record" not updating/writing this last record into the table before printing. How do I get this resolved?

The print command button refers to a macro that pulls up a report, and the report is associated with a query.

6 replies

by bob sellman

Does your Add Record button either put the form in the Additions Allowed mode or perhaps go to a form where the user can add data? It sounds like you need a Save Record button for the user to click on. Data for a new record is not available until a save operation occurs, either by specifically running the DoCmd.Save VBA code or by going to another new record.

If you don't want to have a Save Record button, then you could add the Save command to the macro, or just use VBA code to run the DoCmd.Save command (perhaps after confirming with the user that the new record should be saved).

If your query basically gets all of the data for the record where the record number (or whatever reference number you are using) equals the value on theform, you could use (instead of the macro), VBA code for the OnClick property of the Print button that would be something like this:

Dim lngID as long ' record number or whatever you are using
lngID = me.txtID ' refers to the control containing the record reference number
DoCmd.Save ' save added data
' note that me.txtID will now be blank
DoCmd.OpenReport("MyReport",acViewNormal,,"[ID]=" & lngID)

The OpenReport command where clause ("[ID]=" & lngID) as listed here assumes that the name of the reference number for the record is called ID and is a number. If it is text (and still called ID), substitute the following:

Dim lngID as String ' (or call it strID)
DoCmd.OpenReport("MyReport",acViewNormal,,"[ID]='" & lngID & "'")

The single quotes are required when dealing with a text variable.

by thanh tran

Bob -

Currently it's tied to two sepate forms: 1) Add Only and 2) View/Edit Only. I was able to create the Macros (since I'm not a programming or MS-Access expert), to make the #2 Form work as I wanted.

But, I'm still not able to get the #1 Form (Add Only) to work. I modified my macro as you had suggested - "Save" command, to the Add Form (or should I have picked a different Object Type for that command?). This macro also contains a SelectReport which is tied into a query that is compared to an auto-numbered Field in the Form.

It is still printing only blank reports, so I must assume it's still not saving the record prior to printing???

by mbarker734

Add this line to your print button on click event before the print command line:

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

This will cause the form to refresh prior to printing.

Good luck,

Mark

by thanh tran

Thanks Bob and Mark!

I was finally able to figure out how to write some code in Access, and was able to get the Print button to work. It actually simplified my database a whole lot. Less queries and Filter conditions! Thanks again!

-thanh

This discussion is closed to new replies.