Solved

CurrentDb.Execute not returning RecordsAffected

Posted on 2004-09-25
4
286 Views
Last Modified: 2008-07-02
i cant get the following function to return a value other than 0.

Public Function DaoExecuteSql(SqlStr As String) As Long
On Error GoTo ErrorHandler

   CurrentDb.Execute (SqlStr), dbFailOnError
   DaoExecuteSql = CurrentDb.RecordsAffected

Exit Function
ErrorHandler:
   MsgBox Err.Description, vbCritical
   Exit Function
End Function
0
Comment
Question by:tricks801
  • 3
4 Comments
 
LVL 34

Accepted Solution

by:
flavo earned 500 total points
ID: 12153410
I belive its because using currentdb each time creates a new instance of the db object

so use

Public Function DaoExecuteSql(SqlStr As String) As Long
On Error GoTo ErrorHandler

Dim db as dao.database
Set db = currentdb
   db.Execute (SqlStr), dbFailOnError
   DaoExecuteSql = db.RecordsAffected

Exit Function
ErrorHandler:
   MsgBox Err.Description, vbCritical
   Exit Function
End Function

Dave
0
 
LVL 34

Assisted Solution

by:flavo
flavo earned 500 total points
ID: 12153411
I belive its because using currentdb each time,which creates a new instance of the db object
0
 

Author Comment

by:tricks801
ID: 12153438
thanks
0
 
LVL 34

Expert Comment

by:flavo
ID: 12153853
Cheers mate!

Dave
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
bind Combobox 4 29
Format Meeting Request through VBA 5 20
Error: Operation must use an updateable query 2 10
Access 2010 Query Syntax 5 23
This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now