Clicking a "refresh" button takes me to a new record

A

Amit

Hi,

I have a form to enter data for a budget, and I have
a "refresh" button on the same form to update and display
running totals for the budget (budget total, invoice
total, fees, remaining amount).

When I click on the "Refresh" button, it takes me to a new
record instead of keeping me on the same record. I'm not
sure why this is happening and would appreciate any help
and explanation, or possibly general guidelines/code
behind a "refresh" button.

I open this form through a menu, using "DoCmd.OpenForm
stDocName, , , , acFormAdd" behind a button, and the
Allow Edits/Deletions/Additions and Data Entry properties
of the form are set to "Yes". There is a sub-form on the
form to enter invoice details.

The code behind the "refresh" button is:
===========================================================
Private Sub cmdRefresh_Click()
On Error GoTo Err_cmdRefresh_Click
saverecnum = Me.CurrentRecord
saverecnumsfrm = Me!sfrmInvoiceItem.Form.CurrentRecord
Me.Dirty = False
Me.Requery

DoCmd.GoToRecord , , acGoTo, saverecnum
Me!sfrmInvoiceItem.SetFocus
DoCmd.GoToRecord , , acGoTo, saverecnumsfrm

Me.InvoiceAmount = Me.txtRunningTotal

Exit_cmdRefresh_Click:
Exit Sub

Err_cmdRefresh_Click:
MsgBox Err.Description
Resume Exit_cmdRefresh_Click

End Sub
===========================================================

Thanks!

-Amit
 
A

Amit

Follow-up:
==========
I figured out why this is happening. If I open the form
directly (that is, not through the menu form), or if I
change the DoCmd.OpenForm statement in the menu form to
remove "acFormAdd"; then the "refresh" button on the form
works fine. I also changed the "data entry" property of
the form to "no".

But, does that mean I cannot refresh data on a form (and
return to the same record after refreshing) if it is
opened using "acFormAdd"? Is there a way to get around
this?

I'm sure that my limited knowledge of Access is the
culprit here, and I will appreciate if someone can explain
this to me.

Thanks for reading.

-Amit
 
K

Kelvin

You must be performing the refresh on the entire form. This along with the
data entry property is what is causing the problem. Refresh will repopulate
the form with the current recordset. By having the data entry property set
to yes, you are telling access to only allow the form to show a blank form
with no data. So your refresh command is saving the data then forcing the
form to show the blank form. If you really want to have the data entry
option then use Repaint instead of refresh. This will just tell the current
form to update each text box. If you have a calculation in a text box, this
will update the result.

Kelvin
 

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