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!
6 5452
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? - Dim strSQL As String, qdfTemp As DAO.QueryDef
-
-
strSQL = "<SQL Statement here>;"
-
-
'Create a Tempory Query
-
Set qdfTemp = CurrentDb.CreateQueryDef("", strSQL)
-
-
qdfTemp.Execute
-
-
Debug.Print "Records Affected after Executing Query from QueryDef: " & qdfTemp.RecordsAffected
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? - Dim lngRecsPreAppend As Long, lngRecsPostAppend As Long
-
Dim lngRecordsAffected As Long
-
-
lngRecsPreAppend = DCount("*", "<Your Table Name>")
-
'perform Action (APPEND) Query here
-
lngRecsPostAppend = DCount("*", "<Your Table Name>")
-
-
lngRecordsAffected = (lngRecsPostAppend - lngRecsPreAppend)
-
Debug.Print "Records Affected by Append Query: " & lngRecordsAffected
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
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. -
Dim lngRecsPreAppend As Long, lngRecsPostAppend As Long
-
Dim lngRecordsAffected As Long
-
-
lngRecsPreAppend = DCount("*", "<Your Table Name>")
-
qryInsertKursDeltagare.Execute
-
lngRecsPostAppend = DCount("*", "<Your Table Name>")
-
-
lngRecordsAffected = (lngRecsPostAppend - lngRecsPreAppend)
-
-
If lngRecordsAffected = 0 Then
-
MsgBox "(1) Det gick inte att registrera!", vbExclamation, strFöreningsnamn
-
Exit Sub
-
Else
-
End If
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
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)!
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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: 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...
|
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...
|
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: 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...
|
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,...
| |