Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data edits not always shown when report opened from form 1

Status
Not open for further replies.

cdck

Programmer
Nov 25, 2003
281
US
I have a bound form (NCREdit) on which my users enter information and updates regarding rejections. On this form, there are four subforms and multiple buttons.

Two of the buttons open a report based on the record shown on the form; one opens the report in preview mode, the other prints it straight to the user's default printer.

We have encountered issues where once the data on the main form has been entered, changes to that data are not always applied when the user opens the report. It appears that changes to subform data work correctly. I attempted to fix this issue through the On Click event by adding code to 1) reset the form focus to the date field and 2) refresh the form data before opening the report. Here is the On Click event code currently in use:

[tt]
Private Sub cmdOpenReport_Click()
On Error GoTo Err_cmdOpenReport_Click

Me.NCRDate.SetFocus

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

Dim stDocName As String

stDocName = "NCRreport"
DoCmd.OpenReport stDocName, acPreview, , "NCRno = '" & Me.NCRno & "'"

Exit_cmdOpenReport_Click:
Exit Sub

Err_cmdOpenReport_Click:
MsgBox Err.Description
Resume Exit_cmdOpenReport_Click

End Sub
[/tt]

Although adding these lines to the code appears to have reduced the number of times the issue comes up, it has not stopped it. Can anyone suggest a better way or an additional safeguard?

Cheryl dc Kern
 

It doesn't seem that you've saved your changes when you are opening the report.
So, the report only displays the values that are actually in the table.

Randy
 
This causes questions for me - just trying to understand:

1. The current code changes the focus field and refreshes the form data before opening the report. If I add code to save the record before opening the report, can I safely remove these two steps?

2. If it is not saving the record to the bound table fields, then why does this issue never happen on new records, only on re-editing records that already exist?

3. If a user enters data and closes the form, does this mean that some of their data is being lost?

I've worked with a lot of bound forms in the past, and had no problems like this arise without having to add code to specifically save the record. Now I'm wondering if that's just an issue of luck...

Cheryl dc Kern
 
When you close a form, it loses focus and attempts to write the record to your table.

Just add a line of code to force the save like:
Code:
  Me.Dirty = False
You should be able to remove the other two lines.

Duane
Hook'D on Access
MS Access MVP
 
Thank you very much for the Me.Dirty suggestion. A little research online looking for that particular string brought me to an article at which explained further why this bug can happen, contrary to the information Access publications give you regarding how records are saved. Although that article refers specifically to closing the form, it is easy to see how the same bug would affect my situation.

Thanks again, to both of you.

Cheryl dc Kern
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top