473,396 Members | 1,767 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.

RecordsAffected is zero when it should not be.

Hi,

I have a rather advanced MS Access 2002 solution where I use the RecordsAffected property of the Execute method for a Querydef. I’m using it all over the solution and it has worked as expected for years. Suddenly it does not in parts of the code, since it returns zero even when it should not. In the example below the record is there in table as it should after the execute and I expect RecordsAffected to be one. It is zero. Can anyone explain why this could happen? Is there a work around (other than do a select query that checks that the expected record is there)?

qryInsert.Execute
If qryInsert.RecordsAffected = 0 Then
MsgBox "Failed to insert the person!"
Exit Sub
End If

Thanks!
Nov 23 '07 #1
6 5452
ADezii
8,834 Expert 8TB
Hi,

I have a rather advanced MS Access 2002 solution where I use the RecordsAffected property of the Execute method for a Querydef. I’m using it all over the solution and it has worked as expected for years. Suddenly it does not in parts of the code, since it returns zero even when it should not. In the example below the record is there in table as it should after the execute and I expect RecordsAffected to be one. It is zero. Can anyone explain why this could happen? Is there a work around (other than do a select query that checks that the expected record is there)?

qryInsert.Execute
If qryInsert.RecordsAffected = 0 Then
MsgBox "Failed to insert the person!"
Exit Sub
End If

Thanks!
This is a rather strange result. Are you using the correct Syntax?
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String, qdfTemp As DAO.QueryDef
  2.  
  3. strSQL = "<SQL Statement here>;"
  4.  
  5. 'Create a Tempory Query
  6. Set qdfTemp = CurrentDb.CreateQueryDef("", strSQL)
  7.  
  8. qdfTemp.Execute
  9.  
  10. Debug.Print "Records Affected after Executing Query from QueryDef: " & qdfTemp.RecordsAffected
Nov 24 '07 #2
ADezii
8,834 Expert 8TB
Hi,

I have a rather advanced MS Access 2002 solution where I use the RecordsAffected property of the Execute method for a Querydef. I’m using it all over the solution and it has worked as expected for years. Suddenly it does not in parts of the code, since it returns zero even when it should not. In the example below the record is there in table as it should after the execute and I expect RecordsAffected to be one. It is zero. Can anyone explain why this could happen? Is there a work around (other than do a select query that checks that the expected record is there)?

qryInsert.Execute
If qryInsert.RecordsAffected = 0 Then
MsgBox "Failed to insert the person!"
Exit Sub
End If

Thanks!
As an afterthought, does the following code work in your situation?
Expand|Select|Wrap|Line Numbers
  1. Dim lngRecsPreAppend As Long, lngRecsPostAppend As Long
  2. Dim lngRecordsAffected As Long
  3.  
  4. lngRecsPreAppend = DCount("*", "<Your Table Name>")
  5.   'perform Action (APPEND) Query here
  6. lngRecsPostAppend = DCount("*", "<Your Table Name>")
  7.  
  8. lngRecordsAffected = (lngRecsPostAppend - lngRecsPreAppend)
  9. Debug.Print "Records Affected by Append Query: " & lngRecordsAffected
Nov 24 '07 #3
Hi Adezii,

Thanks for your suggestions. I don’t there is a syntax or program error I my code, but a bug in MS Access. The reason I think that is that the code has worked for years and I have not changed this procedure neither the query involved.

Here is the code for this procedure, with some not relevant parts removed (marked with …)

If you think my naming are strange that because I’m from Sweden.

Private Sub cmdAnmäl_Click()
Dim datKursDeltAnmDatum As Date
Dim strKursDeltFritext As String
Dim dbDenna As Database
Dim qryInsertKursDeltagare As QueryDef
Dim qryKursDeltagare As QueryDef
Dim datKursDeltRegTid As Date
Dim blnVäntlista As Boolean
….
Set dbDenna = DBEngine.Workspaces(0).Databases(0)

Set qryInsertKursDeltagare = dbDenna.QueryDefs("qryInsertKursDeltagare")
……
qryInsertKursDeltagare.Parameters("lngPersonId") = lngPersonID
qryInsertKursDeltagare.Parameters("lngKursId") = lngKursid
qryInsertKursDeltagare.Parameters("strKursDeltFrit ext") = strKursDeltFritext
qryInsertKursDeltagare.Parameters("datKursDeltAnmD atum") = datKursDeltAnmDatum
qryInsertKursDeltagare.Parameters("datKursDeltRegT id") = datKursDeltRegTid
qryInsertKursDeltagare.Parameters("blnKursVäntlist a") = blnVäntlista
qryInsertKursDeltagare.Parameters("strAnledning") = strAnledning
qryInsertKursDeltagare.Parameters("strOCR") = strOCR

qryInsertKursDeltagare.Execute
' RecordsAffected returns zero even when a record was inserted into the table.

Debug.Print qryInsertKursDeltagare.RecordsAffected
If qryInsertKursDeltagare.RecordsAffected = 0 Then
MsgBox "(1) Det gick inte att registrera!", vbExclamation, strFöreningsnamn
Exit Sub
Else
End If
……
End Sub

Best regards

Kent Dahlgren
Nov 24 '07 #4
ADezii
8,834 Expert 8TB
Hi Adezii,

Thanks for your suggestions. I don’t there is a syntax or program error I my code, but a bug in MS Access. The reason I think that is that the code has worked for years and I have not changed this procedure neither the query involved.

Here is the code for this procedure, with some not relevant parts removed (marked with …)

If you think my naming are strange that because I’m from Sweden.

Private Sub cmdAnmäl_Click()
Dim datKursDeltAnmDatum As Date
Dim strKursDeltFritext As String
Dim dbDenna As Database
Dim qryInsertKursDeltagare As QueryDef
Dim qryKursDeltagare As QueryDef
Dim datKursDeltRegTid As Date
Dim blnVäntlista As Boolean
….
Set dbDenna = DBEngine.Workspaces(0).Databases(0)

Set qryInsertKursDeltagare = dbDenna.QueryDefs("qryInsertKursDeltagare")
……
qryInsertKursDeltagare.Parameters("lngPersonId") = lngPersonID
qryInsertKursDeltagare.Parameters("lngKursId") = lngKursid
qryInsertKursDeltagare.Parameters("strKursDeltFrit ext") = strKursDeltFritext
qryInsertKursDeltagare.Parameters("datKursDeltAnmD atum") = datKursDeltAnmDatum
qryInsertKursDeltagare.Parameters("datKursDeltRegT id") = datKursDeltRegTid
qryInsertKursDeltagare.Parameters("blnKursVäntlist a") = blnVäntlista
qryInsertKursDeltagare.Parameters("strAnledning") = strAnledning
qryInsertKursDeltagare.Parameters("strOCR") = strOCR

qryInsertKursDeltagare.Execute
' RecordsAffected returns zero even when a record was inserted into the table.

Debug.Print qryInsertKursDeltagare.RecordsAffected
If qryInsertKursDeltagare.RecordsAffected = 0 Then
MsgBox "(1) Det gick inte att registrera!", vbExclamation, strFöreningsnamn
Exit Sub
Else
End If
……
End Sub

Best regards

Kent Dahlgren
Just for curiosity, why don't you try the simple work-a-around that I had previously listed. If it works, you know it is some kind of problem related to the RecordsAffected Property, if not, it's an Access related issue. If you do decide to test it, please let me know the outcome - you got my curiosity.
Expand|Select|Wrap|Line Numbers
  1. Dim lngRecsPreAppend As Long, lngRecsPostAppend As Long
  2. Dim lngRecordsAffected As Long
  3.  
  4. lngRecsPreAppend = DCount("*", "<Your Table Name>")
  5.   qryInsertKursDeltagare.Execute
  6. lngRecsPostAppend = DCount("*", "<Your Table Name>")
  7.  
  8. lngRecordsAffected = (lngRecsPostAppend - lngRecsPreAppend)
  9.  
  10. If lngRecordsAffected = 0 Then
  11.   MsgBox "(1) Det gick inte att registrera!", vbExclamation, strFöreningsnamn
  12.     Exit Sub
  13. Else
  14. End If
Nov 25 '07 #5
Hi,

I've found the error! One of tables had a field that was incorrect defind. Is was defined to be numeric instead of text. Strange anyway that the record was inserted even though RecordsAffected was zero.

To explain this further, I have tables and code in different files and the tables linked to the program. One of my users had defined a field incorrect and the error occured when I executed the program on a copy of this tables.

Thanks!

Kent
Nov 25 '07 #6
ADezii
8,834 Expert 8TB
Hi,

I've found the error! One of tables had a field that was incorrect defind. Is was defined to be numeric instead of text. Strange anyway that the record was inserted even though RecordsAffected was zero.

To explain this further, I have tables and code in different files and the tables linked to the program. One of my users had defined a field incorrect and the error occured when I executed the program on a copy of this tables.

Thanks!

Kent
Glad 'you' figured it out because it was driving me crazy. (LOL)!
Nov 26 '07 #7

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

Similar topics

4
by: Steven T. Hatton | last post by:
I mistakenly set this to the comp.std.c++ a few days back. I don't believe it passed the moderator's veto - and I did not expect or desire anything different. But the question remains: ISO/IEC...
7
by: Bri | last post by:
Greetings, I have a Passthrough Query to SQL Server that I want to know the RecordsAffected, but it always returns 0. This worked perfectly when it was an Access Query on the ODBC linked...
2
by: Jack | last post by:
It appears that RecordsAffected reports the wrong value when a Null integer or date value is inserted using empty quotes. The insert works fine, but RecordsAffected reports 0 instead of 1. Here...
53
by: Zhiqiang Ye | last post by:
Hi, All I am reading FAQ of this group. I have a question about this: http://www.eskimo.com/~scs/C-faq/q7.31.html It says: " p = malloc(m * n); memset(p, 0, m * n); The zero fill is...
10
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac11/html/acfctNZ_HV05186465.asp "If the value of the variant argument is Null, the Nz function returns the number zero or a...
22
by: spam.noam | last post by:
Hello, I discovered that I needed a small change to the Python grammar. I would like to hear what you think about it. In two lines: Currently, the expression "x" is a syntax error. I suggest...
22
by: semedao | last post by:
Hi , I am using asyc sockets p2p connection between 2 clients. when I debug step by step the both sides , i'ts work ok. when I run it , in somepoint (same location in the code) when I want to...
33
by: Zytan | last post by:
I want to make a zero element array. I know that Nothing is not the same as a zero element array, since I can't get the length of, or iterate through, an array = Nothing. I could make a zero...
15
by: Peng Yu | last post by:
Hi, Suppose T is 'float' or 'double'. T x; x < 10 * std::numeric_limits<T>::epsilon(); I can use the above comparison to test if 'x' is numerically zero. But I'm wondering what should be...
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: 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...
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
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
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...
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.