Solved

CurrentDb.Execute not returning RecordsAffected

Posted on 2004-09-25
4
294 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

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

695 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