473,378 Members | 1,495 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,378 software developers and data experts.

Please help: Query uses _old_ value, but I am using _AfterUpdate_

Hi all,

I created a function that updates a certain status field. The status can be
influenced by four different other fields. So, on the form where I edit
these fields I call the function (see below) from the AfterUpdate events of
each of the four fields.

The problem is, that the query in the function uses the _old_ value of the
updated field! I want it to use the _updated_ value and thought the
_AfterUpdate_ event would do the trick.

Who can tell me what I am doing wrong?
The function I call from the AfterUpdate event is:

Function ReadyForTest(obsid As Integer) As Boolean
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim sSQL As String

Set dbs = CurrentDb()
sSQL = "SELECT Count(*) As MyCount FROM qryReadyForTest " & _
" WHERE Observation_ID = " & obsid
Set rst = dbs.OpenRecordset(sSQL, dbOpenSnapshot)
If rst!MyCount = 0 Then
MsgBox "Do Action"
Else
MsgBox "Ready for test!"
End If
Set rst = Nothing
Set dbs = Nothing

' Succeeded
ReadyForTest = True
End Function

(As you can see there is no status updated yet, but this is only used as an
example)

Kind regards,

Koen
Nov 12 '05 #1
5 1367
Koen wrote:
Hi all,

I created a function that updates a certain status field. The status can be
influenced by four different other fields. So, on the form where I edit
these fields I call the function (see below) from the AfterUpdate events of
each of the four fields.

The problem is, that the query in the function uses the _old_ value of the
updated field! I want it to use the _updated_ value and thought the
_AfterUpdate_ event would do the trick.
How are you passing the value to the function? It appears you are sending an
integer value to it. Are you sure you know what the value is?
Who can tell me what I am doing wrong?
Impossible if we don't know how you are calling the function. Who knows what
qryReadyForTest is.

Who knows. Maybe you need to save the record first before running the
function.
Docmd.RunCommand accmdSaveREcord

The function I call from the AfterUpdate event is:

Function ReadyForTest(obsid As Integer) As Boolean
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim sSQL As String

Set dbs = CurrentDb()
sSQL = "SELECT Count(*) As MyCount FROM qryReadyForTest " & _
" WHERE Observation_ID = " & obsid
Set rst = dbs.OpenRecordset(sSQL, dbOpenSnapshot)
If rst!MyCount = 0 Then
MsgBox "Do Action"
Else
MsgBox "Ready for test!"
End If
Set rst = Nothing
Set dbs = Nothing

' Succeeded
ReadyForTest = True
End Function

(As you can see there is no status updated yet, but this is only used as an
example)

Kind regards,

Koen


Nov 12 '05 #2
Salad <oi*@vinegar.com> wrote in news:3F**************@vinegar.com:

The problem is, that the query in the function uses the _old_ value
of the updated field! I want it to use the _updated_ value and
thought the _AfterUpdate_ event would do the trick.


How are you passing the value to the function? It appears you are
sending an integer value to it. Are you sure you know what the value
is?


This is how I pass the value to the function:
Call ReadyForTest(Me.txtObservation_ID)

Who can tell me what I am doing wrong?


Impossible if we don't know how you are calling the function. Who
knows what qryReadyForTest is.

Who knows. Maybe you need to save the record first before running the
function.
Docmd.RunCommand accmdSaveREcord


Yes! This works! Thanks!
Is it this simple? it looks an odd solution...
But thanks!

Koen

Nov 12 '05 #3
Koen <no@spam.nl> wrote in
news:Xn********************@194.109.133.20:
Salad <oi*@vinegar.com> wrote in
news:3F**************@vinegar.com:

The problem is, that the query in the function uses the
_old_ value of the updated field! I want it to use the
_updated_ value and thought the _AfterUpdate_ event would do
the trick.


How are you passing the value to the function? It appears
you are sending an integer value to it. Are you sure you
know what the value is?


This is how I pass the value to the function:
Call ReadyForTest(Me.txtObservation_ID)

Who can tell me what I am doing wrong?


Impossible if we don't know how you are calling the function.
Who knows what qryReadyForTest is.

Who knows. Maybe you need to save the record first before
running the function.
Docmd.RunCommand accmdSaveREcord


Yes! This works! Thanks!
Is it this simple? it looks an odd solution...
But thanks!

Koen

Yes it is that simple, the reason is that your function reads the
values stored in the table. Until the values in the form are
saved to the table, either by closing the form, going to another
record, or by forcing a save via command. the table still has the
old values in it.

Bob Q
Nov 12 '05 #4
DFS
Issue a Me.Refresh command before calling the function.

"Koen" <no@spam.nl> wrote in message
news:Xn*********************@194.109.133.20...
Hi all,

I created a function that updates a certain status field. The status can be influenced by four different other fields. So, on the form where I edit
these fields I call the function (see below) from the AfterUpdate events of each of the four fields.

The problem is, that the query in the function uses the _old_ value of the
updated field! I want it to use the _updated_ value and thought the
_AfterUpdate_ event would do the trick.

Who can tell me what I am doing wrong?
The function I call from the AfterUpdate event is:

Function ReadyForTest(obsid As Integer) As Boolean
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim sSQL As String

Set dbs = CurrentDb()
sSQL = "SELECT Count(*) As MyCount FROM qryReadyForTest " & _
" WHERE Observation_ID = " & obsid
Set rst = dbs.OpenRecordset(sSQL, dbOpenSnapshot)
If rst!MyCount = 0 Then
MsgBox "Do Action"
Else
MsgBox "Ready for test!"
End If
Set rst = Nothing
Set dbs = Nothing

' Succeeded
ReadyForTest = True
End Function

(As you can see there is no status updated yet, but this is only used as an example)

Kind regards,

Koen

Nov 12 '05 #5
Koen wrote:
This is how I pass the value to the function:
Call ReadyForTest(Me.txtObservation_ID)


That looks OK. CALL is usually for subroutines. Subroutines don't pass
back values. Functions do. Ex:
Dim blnOK As Boolean
blnOK = ReadyForTest(variable)
If blnOK Then...
or
If ReadyForTest(variable) Then...

Subs usually perform an action then return control back to the routine that
called them and continues. No value is returned. Since your Sub, if it
were a function, would always return True, it does not need to be a
function.
Who knows. Maybe you need to save the record first before running the
function.
Docmd.RunCommand accmdSaveREcord


Yes! This works! Thanks!


That's good.

Nov 12 '05 #6

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

Similar topics

13
by: dogu | last post by:
Noob alert. Code is below. File is saved as a .php. What I'm trying to do: User uses 'select' box drop down list to pick a value. Value ($site) is derived from a db query. This works fine....
4
by: Orion | last post by:
Hi, This is kind of last minute, I have a day and a half left to figure this out. I'm working on a project using ms-sqlserver. We are creating a ticket sales system, as part of the system, I...
10
by: motessa | last post by:
Hello All, I am new to Access and have been looking for answers to my problem on the internet and have not found it yet. I hope someone can give me a hint. Thanks so much. I have a form...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
7
by: rguarnieri | last post by:
Hi! I'm trying to create a query with a boolean expression like this: select (4 and 1) as Value from Table1 this query return always -1, but when I make the same calculation in visual...
0
by: plaidthermos | last post by:
hello, i have a database where there is a main table, documents, and then a relationship table doc_topics with one entry for each topic into which a document falls. (any document may have an...
1
PEB
by: PEB | last post by:
POSTING GUIDELINES Please follow these guidelines when posting questions Post your question in a relevant forum Do NOT PM questions to individual experts - This is not fair on them and...
17
by: so many sites so little time | last post by:
all right so the script is pretty simple it goes it retrives what the id of the post is and it lets you edit it well no it doesnt. now if you go to www.kirewire.com/pp2/index/php you will see a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.