Solved

CurrentDb.Execute not returning RecordsAffected

Posted on 2004-09-25
4
292 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
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 …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

730 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