473,387 Members | 1,583 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.

Sometimes, top-values query does not return top-most value ???

MLH
Have a data entry form bound to a table.
Has a save button on it that launches DoCmd.RunCommand acCmdSaveRecord
in Access 97. In the form after-update code, I have a line looking
something like this:

LastVehicleJobID = DLookup("[VehicleJobID]", "qryGetLastVehicleJobID")

qryGetLastVehicleJobID looks something like this:
SELECT TOP 1 tblVehicleJobs.VehicleJobID
FROM tblVehicleJobs
ORDER BY tblVehicleJobs.VehicleJobID DESC;

Immediately after the RunCommand acCmdSaveRecord line,
sometimes the value returned by the top values query is the
ID of not the newly added record, but the one before it. Not all
the time does this happen. But sometimes it happens. Is that
normal? I do not have a DoEvents line after the acCmdSaveRecord
line. Should I have to? Previously, I've been under the impression
that Form AfterUpdate code did not run until the write to the table
had been made and was finished. Is that the way it's supposed to be?
Apr 8 '07 #1
2 2095
It should work if the data is in an Access table (not something linked to a
different database program.)

Instead of the RunCommand, try:
Me.Dirty = False
That should notify you if the record did not save.

Some other cases where it might not work include:
- Existing record (so the entry is not the last one.)
- New record not dirtied (so the last one doesn't match.)
- AutoNumber is Random instead of Incremental.
- Seed of AutoNumber has been reset (usually bug.)
- Another user saved another record since (rare.)

Is there any reason you are looking in the table instead of reading the
value from the form itself? (Access 97 can report the wrong number in
Form_AfterUpdate, and rarely in Form_ BeforeUpdate too, so perhaps you are
trying to avoid this.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"MLH" <CR**@NorthState.netwrote in message
news:jj********************************@4ax.com...
Have a data entry form bound to a table.
Has a save button on it that launches DoCmd.RunCommand acCmdSaveRecord
in Access 97. In the form after-update code, I have a line looking
something like this:

LastVehicleJobID = DLookup("[VehicleJobID]", "qryGetLastVehicleJobID")

qryGetLastVehicleJobID looks something like this:
SELECT TOP 1 tblVehicleJobs.VehicleJobID
FROM tblVehicleJobs
ORDER BY tblVehicleJobs.VehicleJobID DESC;

Immediately after the RunCommand acCmdSaveRecord line,
sometimes the value returned by the top values query is the
ID of not the newly added record, but the one before it. Not all
the time does this happen. But sometimes it happens. Is that
normal? I do not have a DoEvents line after the acCmdSaveRecord
line. Should I have to? Previously, I've been under the impression
that Form AfterUpdate code did not run until the write to the table
had been made and was finished. Is that the way it's supposed to be?
Apr 8 '07 #2
MLH
On Sun, 8 Apr 2007 17:35:40 +0800, "Allen Browne"
<Al*********@SeeSig.Invalidwrote:
>Is there any reason you are looking in the table instead of reading the
value from the form itself? (Access 97 can report the wrong number in
Form_AfterUpdate, and rarely in Form_ BeforeUpdate too, so perhaps you are
trying to avoid this.)
As a matter of fact, I haven't a good reason for reading the table
value instead of reading the AutoNumber field value right off the
form itself. I'm going to start doing just that. None of the other
conditions you pointed out are applicable. Its as if a race condition
exists in the process and the winner is the process trying to read
the new record and the loser is the process writing the new record.
At this point, I don't give a flying shit about the WHY? I'll settle
for the right value - and that will appear in the VehicleJobID field
on the form EVERY time. That much is for certain. Up until yesterday,
I did not have the VehicleJobID field on the data entry form - since
it was not a field that I thought necessary. Big wake up call - here's
a perfectly good reason for it.

Whenever this problem occurred, I've gone back to MAKE SURE THE
NEW RECORD WAS WRITTEN. It was - every single time. For two years,
the procedure in the AfterUpdate code has been reading the new record
ID field value from the table. 99% of the time, it snatches the value
of the NEW record. Every now and then, though, it gets the value of
the last record BEFORE the newly added record is written. I know it
immediately when it happens because letters that should-a-been printed
do not get printed and I find myself going Duhhhhh??????

At first, I was planning on reading the keyfield value of the last
rec in table BEFORE appending a new record, reading it again AFTER
appending the new record and comparing the values to LOOK for this
anomoly. But who the fuck cares about "catching it in the act" of
being wrong. Its too fuckin' late then. I think its a built-in
Micro$oft fuck-up - you know, shit happens. I'd rather have a work-
a-round tthat circumvents the problem than to have the problem and
go "Whoopee! I found it!" I appreciate the feedback.
Apr 8 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Stephane Dalpe | last post by:
Hi all, I just want to know why when I'm installing jdk sometimes ask me to reboot and sometimes he don't. As part of our installation, we launch the jdk installation if it's not already...
2
by: Werner Partner | last post by:
I'm a little confused: htmled phase5 uses this Date-Tag: <!--DATE-->28.03.2004<!--/DATE--> If I try to validate the source, sometimes I get an error, sometimes not. This source:...
6
by: Ron Brennan | last post by:
Good evening. An HTML problem maybe, but one that I think can be solved with JavaScript. I have a page which is supposed to display several small JPEG images using elements like: <image...
6
by: Dot net work | last post by:
I've read quite a few threads on these groups about this. When someone says the following: "My Page_Load gets called twice on a button click postback" The replies are: "Do you have...
1
by: Jeffrey Frabutt | last post by:
Hey... I'm reletively new to ASP.NET and am having some frustrating debugging issues. Everything is configured correctly for me to debug my VERY simple one-page application. That said, after just...
7
by: jw | last post by:
//it sometimes crashes sometimes not why? #include<iostream> #include<fstream> #include<vector> #include<string> #include<ctime> using namespace std; #ifndef NULL #define NULL (short) 0...
2
by: cheers_ye | last post by:
The source of the image is <IMG ID=\"69\" class=\"a10\"...
5
by: David Thielen | last post by:
Hi; We have our app up on a beta server. Sometimes people from outside the firewall get "The page cannot be displayed" when they try to access it. A couple of weird things about this: 1) If...
0
by: comp.lang.php | last post by:
<? header('Pragma: no-cache'); // ENSURE CLIENT-SIDE CACHE FLUSHING $url = "$projectURLPath/index.php"; if ($_REQUEST) $url .= '?logoutMsg='. urlencode($_REQUEST); if ($willAuthenticate &&...
0
by: radiv | last post by:
My code is in ASP.Net. I have loaded a web page into a web browser and have identified the elements on the web page (buttons) using Ihtmldocument and have my code written to the events. ...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.