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

Update query: Number of records.

759 512MB
Hello !

I run this code:
Expand|Select|Wrap|Line Numbers
  1. Call DefaultParameter(Me.Name, "ID_Material", ID_Material) 'for write
  2. x = DefaultParametru(Me.Name, "ID_Material") 'for read
  3.  
  4. Public Function DefaultParameter(Form As String, Param As String, Optional ValParam)
  5. 'Read / Write in table "tblDefault"
  6. Dim SQL As String, Criteria As String
  7.     If IsMissing(ValParam) Then 'Read
  8.         Criteria = "(Form = """ & Form & """) AND (Parameter = """ & Param & """)"
  9.         DefaultParameter = DLookup("Valoare", "tblDefault", Criteria)
  10.     Else 'Write
  11.         DoCmd.SetWarnings False
  12.             SQL = "UPDATE _Default SET [tblDefault].Valoare = " & ValParam & _
  13.                     " WHERE ((([tblDefault].Form)= """ & Form & """)" & _
  14.                     " AND (([tblDefault].Parameter)= """ & Param & """));"
  15.             DoCmd.RunSQL SQL
  16.         DoCmd.SetWarnings True
  17.     End If
  18. End Function
  19.  
As you can see, for write, I use an Update Query.
The "WHERE" clause can find ONE or ZERO record(s).
If WHERE will find ZERO records I wish to run an APPEND query, in order to create the record.
So, the question is: Can I "catch" how many records has been updated ?
If I don't use DoCmd.SetWarnings False, Access say how many records will be updated. So, this information is somewhere in his mind.

Please, do not speak about dCount function. I know about that.

Thank you very much !
Jun 8 '13 #1

✓ answered by ADezii

You can use the RecordsAffected Property of the Database or QueryDef Objects to accomplish this, as in (Expand to see Formatted):
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2.  
  3. strSQL = "UPDATE _Default SET [tblDefault].Valoare = " & ValParam & _
  4.          " WHERE ((([tblDefault].Form)= """ & Form & """)" & _
  5.          " AND (([tblDefault].Parameter)= """ & Param & """));"
  6.  
  7. With CurrentDb
  8.   .Execute strSQL
  9.  
  10.    MsgBox "Number of Records Updated: " & .RecordsAffected
  11. End With

5 3889
ADezii
8,834 Expert 8TB
You can use the RecordsAffected Property of the Database or QueryDef Objects to accomplish this, as in (Expand to see Formatted):
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2.  
  3. strSQL = "UPDATE _Default SET [tblDefault].Valoare = " & ValParam & _
  4.          " WHERE ((([tblDefault].Form)= """ & Form & """)" & _
  5.          " AND (([tblDefault].Parameter)= """ & Param & """));"
  6.  
  7. With CurrentDb
  8.   .Execute strSQL
  9.  
  10.    MsgBox "Number of Records Updated: " & .RecordsAffected
  11. End With
Jun 8 '13 #2
Mihail
759 512MB
Cool !
Thank you, ADezii !!!
Jun 9 '13 #3
ADezii
8,834 Expert 8TB
@Mihail
You are quite welcome, Mihail.
Jun 9 '13 #4
Mihail
759 512MB
Your code, ADezii, is EXACTLY what I need but still I wonder if don't exist a method to test how many records WILL BE affected.
I wonder that because, if I use DoCmd.RunSQL and I do NOT use DoCmd.SetWarnings False, Access will inform me how many records will be updated, BEFORE to start.

Just for theory.
Jun 10 '13 #5
Rabbit
12,516 Expert Mod 8TB
Change the update query to a select query and have it return a count(*). Run that before the update query.

But why do that when you can just turn warnings on? No need to replicate what the warnings does if you don't need to.
Jun 10 '13 #6

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

Similar topics

3
by: Clive Moss | last post by:
Anyone able to help? I want to update a specified number of records that match a criteria. If I use an update query it alters all the records that match - I need to alter only a variable number....
2
by: JMCN | last post by:
hi i need some advice on whether if it would be better to use an append query or an update query. here is the situation, i have linked another database table to my current database. then i...
2
by: bobabooey2k | last post by:
I have an update query with one field having in its "Update to" cell a DLookup statement. This query takes 2-3 minutes on 3000 records. Can I avoid dlookup here using multiple queries? An...
1
by: G Gerard | last post by:
Hello I am trying to update a table (TableB) using records from a second table (TableA)
3
by: rdraider | last post by:
Hi all, Any thoughts on the best way to run an update query to update a specific list of records where all records get updated to same thing. I would think a temp table to hold the list would be...
6
by: Dixie | last post by:
I have asked this question before, but I could not get the suggested solution work. So I will give more details this time. I have an append query that adds several hundred records to a table...
1
by: M3lancholy | last post by:
I've created a database in Microsoft Access 2003, Windows XP. It updates based on: a date range, and various other field matches. It takes this data from a form. What I'm confused about is that...
3
by: ringer | last post by:
I am trying to add a functionality into a db I use for my checkbook that will help me plan for and save money for future large expenses. Into a table called tblFutureTransactions I want to enter...
13
by: Neil | last post by:
I'm running an update query in SQL 7 from QA, and it runs forever. Has been running for 20 minutes so far! The query is quite simple: update a single field in a table, based on a join with another...
33
by: mjvm | last post by:
HI, I have a main table (tblStudents) that holds students where the unique field is StudentID; and a related table (tblNotes) on a one-to-many relationship, where the unique field is NotesID, and...
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:
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: 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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.