473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

After Update Event, cursor jumps from the record in which I made the change to top...

kcdoell
230 100+
Hello:

I have a continuous form that displays records. In the AfterUpdate event of one of the fields, Binding_Percentage, I have the following code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Binding_Percentage_AfterUpdate()
  2. 'Updates the Total calculation in the control "SumGWP" and "SUMNWP"on the quick reference
  3. 'table on the Forecast form
  4.  
  5.     With Me![SumGWP] And Me![SumNWP] And Me![Sum50GWP] And Me![Sum50NWP]
  6.     DoCmd.Requery
  7.  
  8.   End With
  9. End Sub
  10.  
Basically, in my field Binding_Percentage a user can select various choices from a drop down list I created. Depending on their choice, through the above mentioned code, I am refreshing various unbound fields on summary table that I created on the form. This all works great except that since I am doing a DoCmd.Requery the cursor jumps from the record in which I made the change jumps to the first record on the list.

So let’s say there were 5 rows each row representing a record on my form and I made a change on row 3, after the change the cursor would jump to row 1.

I believe this is happen because at the same time I must be requerying the form thus impacting the record source since it is set to a query I built.

How can I stop that from happen?? Any ideas??

Thanks,

Keith.
Apr 30 '08 #1
26 4101
Stewart Ross
2,545 Expert Mod 2GB
Hi Keith. A requery carried out on the form resets the current record back to the beginning of the recordset, which is not what you need. You need to requery the affected fields only, and this is not done with a Docmd.

For future reference, trying to use With in an ANDed form is incorrect, and anyway a With is not needed here as you are not referring to a list of properties belonging to a common control.

Replace your code with
Expand|Select|Wrap|Line Numbers
  1. Private Sub Binding_Percentage_AfterUpdate()
  2. 'Updates the Total calculation in the control "SumGWP" and "SUMNWP"on the quick reference
  3. 'table on the Forecast form
  4.  
  5. Me![SumGWP].Requery
  6. Me![SumNWP].Requery
  7. Me![Sum50GWP].Requery
  8. Me![Sum50NWP].Requery
  9.  
  10. End Sub
  11.  
-Stewart
Apr 30 '08 #2
kcdoell
230 100+
Hi Keith. A requery carried out on the form resets the current record back to the ..................].Requery
Me![Sum50NWP].Requery

End Sub
[/code]
-Stewart

Stewart:

Thanks for the idea I am going to get back to you but I need to run off to a meeting............

Thanks!
Apr 30 '08 #3
kcdoell
230 100+
Stewart:

Okay, I changed the code to the following like you inidicated:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Binding_Percentage_AfterUpdate()
  2. 'Updates the Total calculation in the control "SumGWP", Sum50GWP, "SUMNWP" and Sum50NWP
  3. 'on the quick reference table on the Forecast form
  4.  
  5.     Me![SumGWP].Requery
  6.     Me![SumNWP].Requery
  7.     Me![Sum50GWP].Requery
  8.     Me![Sum50NWP].Requery
  9.  
  10. End Sub
  11.  
And nothing happens (does not requery). No errors were hit. Did I miss something?

Thanks,

Keith.
Apr 30 '08 #4
kcdoell
230 100+
Stewart:

I am trying to understand what is going on so I focused just on my AfterUpdate Event of Binding_Percentage with just one of the controls:

Expand|Select|Wrap|Line Numbers
  1.  
  2.     Me.SumGWP.Requery
  3.  
  4. End Sub
  5.  
So no matter how I write the Me. expression (with [ ], ! or .), still nothing happens. I do though see visually on the form that my "SumGWP" is going through the process of requering. I say this because it blanks out for a nano second and then reappears.

In the control source of "SumGWP" I have the following:

Expand|Select|Wrap|Line Numbers
  1. =DSum("[GWP]","ReQryForecast","Val([Binding_Percentage]) >= 75")
  2.  
Could my issue somehow be in here? Not too sure what the docmd.Requery was doing differently?

All I know is that if I put back the following:

Expand|Select|Wrap|Line Numbers
  1.  
  2.      With Me.SumGWP
  3.           DoCmd.Requery
  4.     End With
  5.  
  6. End Sub
  7.  
My SumGWP recalculates.......but my jumping problem comes back

Any ideas,

Keith.
Apr 30 '08 #5
kcdoell
230 100+
Stewart:

In fact conducting some other experiments the:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Binding_Percentage_AfterUpdate()
  2. 'Updates the Total calculation in the control "SumGWP", Sum50GWP, "SUMNWP" and Sum50NWP
  3. 'on the quick reference table on the Forecast form
  4.  
  5.     DoCmd.Requery
  6.  
  7.     End Sub
  8.  
Is the only thing that updates the "SumGWP" calculation..

Now I am really confused....

Keith.
Apr 30 '08 #6
Stewart Ross
2,545 Expert Mod 2GB
Hi Keith. The DSUM will not be updated unless the current record has actually been stored - not just one of its fields updated. If you update any field value the record is marked as 'Dirty' by Access (their jargon for altered) but not stored until you tab or mouse off the record. Without the record being stored the Requeries are operating on the previous values. The DoCmd execution is different, as to do the requery the 'dirty' record is stored first.

If I am right you should be able to resolve this by placing the following line before the requeries
Expand|Select|Wrap|Line Numbers
  1. me.dirty = false
which will save the record for you.

-Stewart
Apr 30 '08 #7
kcdoell
230 100+
Stewart:

Thanks for getting back to me. I did as you said and it worked! I was also reading and applied the Me.Refresh all by its lonesome in the AfterUpdate event and that worked as well.

In the end, I left your solution since that was what I was shooting for, thanks!! But I am curious how the Me.Refresh works......... If you have any other great insights let me know.

I like how you explain what is happening, it helps to "really" understand what is going on....

Keith.
Apr 30 '08 #8
NeoPa
32,556 Expert Mod 16PB
...
Expand|Select|Wrap|Line Numbers
  1. me.dirty = false
which will save the record for you.

-Stewart
Are you sure Stewart?

I thought that would tell the form that the record needn't be saved (without saving it), rather than actually saving it?

This is quite an old concept (from early OS work) where there is a Dirty flag for each buffer to indicate to the OS whether or not the buffer needs to be flushed to disk.

Saving the record (flushing) doesn't remove the data, but sets the Dirty flag to FALSE.

Setting the flag to FALSE manually, causes the automatic saving (flushing) to be omitted as it thinks there is nothing to save.

Any change to the record (buffer) automatically causes the flag to be set to TRUE.
May 1 '08 #9
Stewart Ross
2,545 Expert Mod 2GB
Hi NeoPa. I did test it out myself, and it does indeed save the record. Anti-intuitive I know - and when I first saw this solution (from another excellent contributor to this very forum! - thread linked here) I was sceptical - but it works. I would rather have an explicit command such as me.save though (and not one of the old menu-based DoCmds which some people use to save the record).

-Stewart
May 1 '08 #10
Stewart Ross
2,545 Expert Mod 2GB
Hi Keith. Refresh updates the records to show all changes made; requery can do the same, but in addition it will show all new records added and remove records deleted by other users, which refresh does not do. In the context of the DSUM performed by your unbound fields saving the record occurs both with the refresh and with setting me.dirty false. As you will see from NeoPa's post, the use of me.dirty in this way is distinctly non-standard in terms of database practice in general, so refresh may be more correct in this circumstance.

The use of requery in a form context is usually more localised to specific controls (such as combo boxes) where an update has taken place and dependent values need to be requeried to refresh them. In my experience it is more unusual to requery the form's own recordset, as to do so resets the current record pointer as discussed in post 2. Refresh appears a better choice in the circumstances.

-Stewart
May 1 '08 #11
NeoPa
32,556 Expert Mod 16PB
... I would rather have an explicit command such as me.save though (and not one of the old menu-based DoCmds which some people use to save the record).

-Stewart
Amen to that Stewart.

I could never find a good explanation for why a Save is done via DoCmd (at least why Me.Save is not at least an option).

PS. I did check the Help and it was quite sensible about how it described the Dirty flag. That is excepting of course, that it was inaccurate :(
May 1 '08 #12
kcdoell
230 100+
Hello:

I thought I was done with this one but a user who is testing my DB just pointed out a problem.

I used the following in the afterupdate event:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Binding_Percentage_AfterUpdate()
  2. 'Updates the Total calculation in the control "SumGWP", Sum50GWP, "SUMNWP" and Sum50NWP
  3. 'on the quick reference table on the Forecast form.  
  4.  
  5. Me.Refresh
  6.  
  7. End Sub
  8.  
Basically, once I change the Binding_Percentage and tab into another field on the same row my numbers (My unbound controls that are performing a calculation) change appropriately but the minute I click on to another row (using the mouse or tab) on my table the numbers change. It looks like the numbers change to the old settings. When I click back to the row I changed the numbers go back to what they are supposed to reflect. I changed the code to the following (Stewart's Suggestion):
Expand|Select|Wrap|Line Numbers
  1. Private Sub Binding_Percentage_AfterUpdate()
  2. 'Updates the Total calculation in the control "SumGWP", Sum50GWP, "SUMNWP" and Sum50NWP
  3. 'on the quick reference table on the Forecast form.  
  4.  
  5.  Me.Dirty = False
  6.     Me![SumGWP].Requery
  7.     Me![Sum50GWP].Requery
  8.     Me![SumNWP].Requery
  9.     Me![Sum50NWP].Requery
  10.  
  11.    End Sub
  12.  
But the same strange thing happens......


Any ideas,

Keith.
May 19 '08 #13
kcdoell
230 100+
Stewart:

I was just experimenting and when I put back my old method that created the jumping to the first record issue:

Expand|Select|Wrap|Line Numbers
  1.  With Me![SumGWP] And Me![SumNWP] And Me![Sum50GWP] And Me![Sum50NWP]
  2.     DoCmd.Requery
  3.     End With
  4.  
I did not have this problem where values would revert back to previous ones once a user clicked on other rows on the form.

Any ideas? This is a show stopper for me..

Thanks,

Keith.
May 19 '08 #14
NeoPa
32,556 Expert Mod 16PB
Is this the same database that you're working on in the Query results based on two control fields, I am at wits end....... thread?
May 20 '08 #15
kcdoell
230 100+
Is this the same database that you're working on in the Query results based on two control fields, I am at wits end....... thread?
NeoPa:

Yes, it is the same database.
May 20 '08 #16
NeoPa
32,556 Expert Mod 16PB
OK Keith. I'll arrange further via PM in that case.
May 20 '08 #17
kcdoell
230 100+
OK Keith. I'll arrange further via PM in that case.

NeoPa:
Could my problem be that my [SumGWP], [Sum50GWP],
[SumNWP], [Sum50NWP], are Calculated Controls and are not Bound Controls. If I was to try to build a query to do the calculations and then bound the controls to that RecordSource, would make this problem go away? I am thinking that it should not make a difference. I was reading something I do not fully understand; that since my form is continous the many instances of this Control on the Continuous Form will display the same value in all instances....

Does that make sense to you?

Keith.
May 20 '08 #18
NeoPa
32,556 Expert Mod 16PB
Until you mentioned the Continuous Forms bit with the unbound controls, No.

After that it all started to make sense. Yes, if you have unbound controls on a continuous form you would certainly expect for those controls all to have the same data (In reality "All" is a misnomer as they are actually multiple displays of the same control).

The suggested solution of working them out in the query coming in to the form seems a workable and eminently sensible one.
May 20 '08 #19
missinglinq
3,532 Expert 2GB
Stewart, when you say

not one of the old menu-based DoCmds which some people use to save the record
I assume you're referring to

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70


You actually can use

DoCmd.RunCommand acCmdSaveRecord

I just use

If Me.Dirty Then Me.Dirty = False

because I learned it first and I can never remember the the exact command acCmdSaveRecord without looking it up!

Linq ;0)>
May 20 '08 #20
kcdoell
230 100+
NeoPa:
I have been trying to convert my code in a query. I had the following in the unbound's control, control source:

Expand|Select|Wrap|Line Numbers
  1. Sum50GWP: =Nz(DSum("[GWP]","ReQryForecast","[Binding_Percentage] = 50"),0)
That gave me zero if the result was null

Now for the query approach:

I thought I would do the following:

Expand|Select|Wrap|Line Numbers
  1. Field: Sum(Nz([tblAllForecast.GWP],0))
  2. Table: 
  3. Total: Expression
  4. Criteria: [Binding_Percentage]=50
  5.  
But I can not seem to incorporate the null result, meaning it will display blank instead of a 0.

Why should it be so different. Thanks for all you help. I am feeling pretty dumb today...

Thanks,

Keith.
May 20 '08 #21
NeoPa
32,556 Expert Mod 16PB
A number of things spring to mind, although I wouldn't expect the effect you describe to be the result of any of them.
  1. Sum(Nz([tblAllForecast.GWP],0)) should probably be Sum(Nz(tblAllForecast.GWP,0))
  2. In the query you are getting the data from a source of [tblAllForecast] whereas in the control it comes from [ReQryForecast].
  3. In the query it's hard to determine whether the criteria is being applied before or after processing the data. It looks like it's after (SQL - HAVING) which makes little sense. The Control would be equivalent to a WHERE.
  4. NB. You are calling the Nz() in the control AFTER the summing. In the query you are doing it before.
PS. When posting queries it's usually better to post the equivalent SQL rather than what is shown in the Query grid.
May 20 '08 #22
kcdoell
230 100+
A number of things spring to mind, although I wouldn't expect the effect you describe to be the result of any of them.
  1. Sum(Nz([tblAllForecast.GWP],0)) should probably be Sum(Nz(tblAllForecast.GWP,0))
  2. In the query you are getting the data from a source of [tblAllForecast] whereas in the control it comes from [ReQryForecast].
  3. In the query it's hard to determine whether the criteria is being applied before or after processing the data. It looks like it's after (SQL - HAVING) which makes little sense. The Control would be equivalent to a WHERE.
  4. NB. You are calling the Nz() in the control AFTER the summing. In the query you are doing it before.
PS. When posting queries it's usually better to post the equivalent SQL rather than what is shown in the Query grid.
To tell you the truth, this thing did work until somebody noticed the the calculations where reverting to the past when they clicked into another record row that was being displayed. It is almost like the Cache is not being cleared. Now I am trying to build a query that will perform the calculation, serve as the contol source, but in my mind I still am going to point the contol source to a query which, your right, I am was already pointing to ([ReQryForecast]). The only difference being that I won't have to do a Dsum? or Sum???

Because I have never done this before I must be me misunderstanding how to point unbound controls based on a query (that perfoms calculations).



Keith.
May 20 '08 #23
kcdoell
230 100+
Solved It!

Refreshing a contol on a form

Thanks,

Keith.
May 20 '08 #24
NeoPa
32,556 Expert Mod 16PB
That doesn't seem right Keith. Binding and refreshing (or requerying) are two separate things.

I think you need to bind. That is to say you need to set the Control Source property to one of the fields returned by the underlying recordset (table or query).
May 21 '08 #25
kcdoell
230 100+
That doesn't seem right Keith. Binding and refreshing (or requerying) are two separate things.

I think you need to bind. That is to say you need to set the Control Source property to one of the fields returned by the underlying recordset (table or query).

If I really knew what that meant, I am just relieved that the problem went away...... I think permanently. For now, I need to move on to other pressing issues. I can always double back when time allots.

Keith.
May 21 '08 #26
NeoPa
32,556 Expert Mod 16PB
I can't argue with that. At least the point is made in here for when you (or anyone else for that matter) want to revisit the issue :)
May 21 '08 #27

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: David | last post by:
Hi I use a calendar to update a field and the after update event no longer works, if i manually update it there is not a problem. How can I get this event to trigger Thanks in advance Dave
1
by: Tony | last post by:
Hi, In a form, when I modify some data and move to the next record, I want be able to trap an event and do a query to check on the change done to the table. Currently, I use the form After...
3
by: visionstate | last post by:
Hi All, I have put the following code in the 'After Update' of a combo box: Private Sub ComboTeam_AfterUpdate() lblSurnameNotify.Visible = True Me!ComboSurname = Null Me!ComboSurname.Requery...
1
by: Dave | last post by:
I'm having problems with certain fields that I force an update (Me.dirty=false) in the After Update Event I lose focus of the field where the user was or where he clicked help Is there a way...
0
by: Kaspa | last post by:
Hello, I have been trying to goto the next record once I update the subform. anybody knows how I can accomplish this. Thanks in advance. Kasparov
4
by: Mikep99 | last post by:
I am new to access and need some help with coding. I have a main form XYZ with 2 subforms. I have a checkbox on subform1 "frmExpediteS" that when checked i would like the Value in Feild "PO" of this...
4
by: injanib via AccessMonster.com | last post by:
I have a combo box called "Recipient" who's row source is a table called "Main" with three columns. The three columns are "Name", "Floor", "Location". Following the combo box are two fields called...
5
by: Zeeshan7 | last post by:
After Update Event Procedure on a form is not working after upsizing database to SQL server. Anything to add in below code as it generate run time error 3622 "You must use the dbSeeChanges option...
14
Rozeanna Jerry
by: Rozeanna Jerry | last post by:
Hi Experts, am new to access. I juts created a form with sub form based on two tables having 1: many relationship. The main form is from tblStudents and subform is from tble attendance. First...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.