refresh form button and stay on current record

  • Thread starter jubiiab via AccessMonster.com
  • Start date
J

jubiiab via AccessMonster.com

Hi,

I have seen some examples on this site but I can’t figure it out. I have a
refresh button on my form and this is the code:

Private Sub refresh_Click()
On Error GoTo Err_refresh_Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

Forms!frm_Machine!MachineNr.SetFocus
DoCmd.Requery ""

Exit_refresh_Click:
Exit Sub

Err_refresh_Click:
MsgBox Err.Description
Resume Exit_refresh_Click

End Sub


When I press the refresh button on my form it goes back to the first record.
I want to stay on the current record. Can some one please help me with
rewriting the above code please???
 
J

jubiiab via AccessMonster.com

I forgot to write that I need the “Requery†code and not the “Refresh†code.
It has to refresh all old and new data because I have more than 4-5 users
running the application.
 
T

tina

it's not the Refresh action that's moving the focus to the first record.
it's the Requery action. if you requery the form, there's no point in
refreshing it. which do you want to do? to decide, read up on both actions
in Help, so you'll understand how each works, and the difference between
them.

hth
 
J

jubiiab via AccessMonster.com

I know it’s the Requery action that moving the focus to the first record. But
I need that action because it has to update all new records and values. I do
understand the difference between Requery and Refresh action. So I need the
Requery action and some how it has to go back to the current record.
it's not the Refresh action that's moving the focus to the first record.
it's the Requery action. if you requery the form, there's no point in
refreshing it. which do you want to do? to decide, read up on both actions
in Help, so you'll understand how each works, and the difference between
them.

hth
[quoted text clipped - 21 lines]
I want to stay on the current record. Can some one please help me with
rewriting the above code please???
 
L

Linq Adams via AccessMonster.com

To set a "bookmark" if you will (an actual bookmark isn't accurate if records
are d/c'd or added) requery then go back to the same record

Where [UniqueField] is a field unique to only one record.

Where [UniqueField] is Text

Dim RecUF as String

RecUF = Me!UniqueField
Me.Requery
Me.Recordset.FindFirst "[UniqueField] = '" & RecUF & "'"

Where [UniqueField]is Numeric

Dim RecUF as (Fill in number type here)

RecUF = Me!UniqueField
Me.Requery
Me.Recordset.FindFirst "[UniqueField] = " & RecUF
 
J

jubiiab via AccessMonster.com

Below you can see the code I have used but now when I click the refresh
button a message comes up that says "overflow" and it's not refreshing the
form??

Private Sub refresh_Click()
On Error GoTo Err_refresh_Click

Dim RecUF As Integer

RecUF = Me!MachineNr
Me.Requery
Me.Recordset.FindFirst "[MachineNr] = " & RecUF

Exit_refresh_Click:
Exit Sub

Err_refresh_Click:
MsgBox Err.Description
Resume Exit_refresh_Click

End Sub

Linq said:
To set a "bookmark" if you will (an actual bookmark isn't accurate if records
are d/c'd or added) requery then go back to the same record

Where [UniqueField] is a field unique to only one record.

Where [UniqueField] is Text

Dim RecUF as String

RecUF = Me!UniqueField
Me.Requery
Me.Recordset.FindFirst "[UniqueField] = '" & RecUF & "'"

Where [UniqueField]is Numeric

Dim RecUF as (Fill in number type here)

RecUF = Me!UniqueField
Me.Requery
Me.Recordset.FindFirst "[UniqueField] = " & RecUF
 
J

jubiiab via AccessMonster.com

No one can help me??? :eek:(
Below you can see the code I have used but now when I click the refresh
button a message comes up that says "overflow" and it's not refreshing the
form??

Private Sub refresh_Click()
On Error GoTo Err_refresh_Click

Dim RecUF As Integer

RecUF = Me!MachineNr
Me.Requery
Me.Recordset.FindFirst "[MachineNr] = " & RecUF

Exit_refresh_Click:
Exit Sub

Err_refresh_Click:
MsgBox Err.Description
Resume Exit_refresh_Click

End Sub
To set a "bookmark" if you will (an actual bookmark isn't accurate if records
are d/c'd or added) requery then go back to the same record
[quoted text clipped - 16 lines]
Me.Requery
Me.Recordset.FindFirst "[UniqueField] = " & RecUF
 
L

Linq Adams via AccessMonster.com

Overflow errors mean that you're trying to put ten pounds of potatoes in a
five pound sack!

You have RecUF Dimmed as an Integer and I'm guessing your machine numbers
run in excess of 32767, which is he maximum number that can be stored in an
Integer field. Try changing Integer to Long and see what happens.

BTW, I did reproduce your error by creating your scenario and entering 33000.
 
J

jubiiab via AccessMonster.com

Thank you very much for your help Linq Adams. It's working now. Sorry I
answered so late but I thought no body had replayed my post. Thank you thank
you thank you!!!! :)
 

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

Similar Threads


Top