Connecting Tech Pros Worldwide Forums | Help | Site Map

Maintaining selected record on requery

Newbie
 
Join Date: May 2007
Posts: 2
#1: May 7 '07
Windows XP
MS Access 2000

Hello folks. First timer here. Have a problem with a form.

I am trying to open a report using a button on a form. The report will use information from a table which is particular to the record being viewed on the form at the time. I want to include any data that the user has input into the form directly before clicking the button. For this reason, I am using the requery function in the macro before opening the report. The trouble is, that this sends the form back to record no. 1.

This is part of a wider problem for me. It is essential on this form that all information and all coded calculations are completed before various reports are opened. I have even included a 'Calculate' button on the form to re-run any code and ensure that all data is current before reports are generated. The trouble is that the user has to remember to click this before printing anything.

I have been trying to get around the problem with non-record specific reports by closing the form and opening it again via macro. This is not a very classy way of doing things, but I'm a bit stuck. I suppose the short summary is: Is there a way of updating the table data from a form(just like you do when you move from one record to another) directly before generating a report and without changing the record in view?

missinglinq's Avatar
Moderator
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 3,004
#2: May 8 '07

re: Maintaining selected record on requery


DoCmd.RunCommand acCmdSaveRecord

will save the record to the table. Place it as the first line of code behind the button that opens the report.
JConsulting's Avatar
Expert
 
Join Date: Apr 2007
Location: Houston
Posts: 601
#3: May 8 '07

re: Maintaining selected record on requery


Quote:

Originally Posted by Bad Horsey

Windows XP
MS Access 2000

Hello folks. First timer here. Have a problem with a form.

I am trying to open a report using a button on a form. The report will use information from a table which is particular to the record being viewed on the form at the time. I want to include any data that the user has input into the form directly before clicking the button. For this reason, I am using the requery function in the macro before opening the report. The trouble is, that this sends the form back to record no. 1.

This is part of a wider problem for me. It is essential on this form that all information and all coded calculations are completed before various reports are opened. I have even included a 'Calculate' button on the form to re-run any code and ensure that all data is current before reports are generated. The trouble is that the user has to remember to click this before printing anything.

I have been trying to get around the problem with non-record specific reports by closing the form and opening it again via macro. This is not a very classy way of doing things, but I'm a bit stuck. I suppose the short summary is: Is there a way of updating the table data from a form(just like you do when you move from one record to another) directly before generating a report and without changing the record in view?

Try using

IF me.dirty = true then
me.dirty = false
end if

it commits the record you're on.
missinglinq's Avatar
Moderator
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 3,004
#4: May 8 '07

re: Maintaining selected record on requery


BTW, if you ever have to requery and want to return to the record you started out in
Expand|Select|Wrap|Line Numbers
  1. Dim holdID
  2. holdID = Me!YourPrimaryKeyName
  3.    Me.Requery
  4.    Me.Recordset.FindFirst "YourPrimaryKeyName = '" & holdID & "'"
Newbie
 
Join Date: May 2007
Posts: 2
#5: May 8 '07

re: Maintaining selected record on requery


Thanks guys. That gives me a much better chance.
Reply