Returning to Current Record After Requery

G

Guest

I have a form that presents the total value of services rendered by
ProjectNumber. The main form is Unbound. The first continuous subform is
based on a query that shows the project number, project name, the total total
staff hours, and the total dollar value. It has a command button that
executes a query, writing the invoice date to the relevant time records, and
changing their status from "Posted" to "Billed".

A second subform shows the detail breakdown for each project by staff
member, linked by an unbound control, txtProjectNumber, on the main form that
is written to by the 1st subform's On Current event.

Our principal reviews this list, and presses the button. Because there is a
small chance that someone has posted additional records while he has the form
loaded, I do a requery to check the current total against the what was
displayed. When I press the button for the first record on the list, the
following code works as intended, however, if I press a different one, the
original amount from that record is compared to the requeried total for the
first one, presumably because the cursor is placed on the first record after
the requery.

I could always use DLookup() to find the new value, but I'd rather just
return the cursor to the original record. Can anyone tell me how to do this?

Thank you.
Sprinks

Dim db As DAO.Database
Dim curTotal As Currency
Dim curNewTotal As Currency
Dim strResponse As String
Dim strSQL As String
Dim rst As DAO.Recordset
Dim strProject As String

Set db = DBEngine(0)(0)

' Remember displayed value of total $
curTotal = Me![txtExtd]

' Requery 1st subform
Me.Requery

' Requery 2nd subform
Me.Parent.ProjectDetail.Requery

' Get requeried value.
' Need to return to original record here.
curNewTotal = Me![txtExtd]

If curTotal <> curNewTotal Then
' Display warning. Let user continue or cancel.
 
R

ruralguy via AccessMonster.com

Before the Requery, save the PK value of the Current Record and then do a
FindFirst after the Requery.
I have a form that presents the total value of services rendered by
ProjectNumber. The main form is Unbound. The first continuous subform is
based on a query that shows the project number, project name, the total total
staff hours, and the total dollar value. It has a command button that
executes a query, writing the invoice date to the relevant time records, and
changing their status from "Posted" to "Billed".

A second subform shows the detail breakdown for each project by staff
member, linked by an unbound control, txtProjectNumber, on the main form that
is written to by the 1st subform's On Current event.

Our principal reviews this list, and presses the button. Because there is a
small chance that someone has posted additional records while he has the form
loaded, I do a requery to check the current total against the what was
displayed. When I press the button for the first record on the list, the
following code works as intended, however, if I press a different one, the
original amount from that record is compared to the requeried total for the
first one, presumably because the cursor is placed on the first record after
the requery.

I could always use DLookup() to find the new value, but I'd rather just
return the cursor to the original record. Can anyone tell me how to do this?

Thank you.
Sprinks

Dim db As DAO.Database
Dim curTotal As Currency
Dim curNewTotal As Currency
Dim strResponse As String
Dim strSQL As String
Dim rst As DAO.Recordset
Dim strProject As String

Set db = DBEngine(0)(0)

' Remember displayed value of total $
curTotal = Me![txtExtd]

' Requery 1st subform
Me.Requery

' Requery 2nd subform
Me.Parent.ProjectDetail.Requery

' Get requeried value.
' Need to return to original record here.
curNewTotal = Me![txtExtd]

If curTotal <> curNewTotal Then
' Display warning. Let user continue or cancel.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top