Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 2 / September 2007

Tip: Looking for answers? Try searching our database.

Problem with records affected

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Markm-s - 13 Sep 2007 16:18 GMT
I'm inserting into a database and need to know the number of records that
where entered and the number of errors, using this
    With CurrentDb
       .Execute strSQL_insert
       If Line_Number = 80 Then
         MsgBox (.RecordsAffected)
       End If
       If .RecordsAffected = 1 Then
         Good_Records = Good_Records + 1
       Else
         Bad_Records = Bad_Records + 1
       End If
     End With
But the recordaffected comes out with 0.

Thanks
Allen Browne - 13 Sep 2007 16:24 GMT
Suggestions:
1. Use a Database variable, so you can set it to Nothing again at the end.

2. Use dbFailOnError so you can see if something goes wrong.

3. Assign RecordsAffected to a variable in case some other process is
involved.

This kind of thing:
   Dim db As DAO.Database
   Dim lngCount as Long
   Set db = CurrentDb()
   db.Execute strSql, dbFailOnError
   lngCount = db.RecordsAffected
   Set db = Nothing
   If lngCount = 1 Then ...

Signature

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.

> I'm inserting into a database and need to know the number of records that
> where entered and the number of errors, using this
[quoted text clipped - 12 lines]
>
> Thanks
Pieter Wijnen - 13 Sep 2007 16:45 GMT
Also if dealing with SQLServer (doesn't hurt anyhow)
   db.Execute strSql, dbFailOnError + dbSeeChanges

Pieter

> Suggestions:
> 1. Use a Database variable, so you can set it to Nothing again at the end.
[quoted text clipped - 29 lines]
>>
>> Thanks
Markm-s - 13 Sep 2007 16:50 GMT
Sadly I now get a data type mismatch in the db.execute line.

> Suggestions:
> 1. Use a Database variable, so you can set it to Nothing again at the end.
[quoted text clipped - 29 lines]
> >
> > Thanks
Allen Browne - 13 Sep 2007 17:28 GMT
If you actually get the mismatch on the Dim db line, you need to set a
reference to the DAO library:
   http://allenbrowne.com/ser-38.html

If you actually get it on the Execute line, something else is wrong. I've
assumed you have declared:
   Dim strSql As String
and set strSql to a valid action query statement.

Signature

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.

> Sadly I now get a data type mismatch in the db.execute line.
>
[quoted text clipped - 31 lines]
>> >      End With
>> > But the recordaffected comes out with 0.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.