[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

CurrentDb.Execute not returning RecordsAffected

Posted on 2004-09-25
4
Medium Priority
?
317 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 2000 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

656 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