473,382 Members | 1,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Capture Success or Failure For Query Run From Code

Hi,

I am building an application in Access 2003. I would like to capture the error for the following query, like "No Record Found". Right now if the record does not exist Access pops the End/Debug error box up.

Dim dbThisDatabase As DAO.Database
Dim rstGetRecord As DAO.recordset
Dim qdf As DAO.QueryDef

Set dbThisDatabase = CurrentDb
Set qdf = dbThisDatabase.QueryDefs("qryExLoginSelect")
qdf.Parameters("qryParcelID") = Me.[parcel ID]
Set rstGetRecord = qdf.OpenRecordset


The other thing I would like to do is capture the number of records added for the following code.

DoCmd.SetWarnings False
DoCmd.OpenQuery "qryExemptAddRecord"
DoCmd.SetWarnings True

Thanks for any help anyone can provide.

Greg
Jul 26 '07 #1
1 2529
Lysander
344 Expert 100+
Hi,

I am building an application in Access 2003. I would like to capture the error for the following query, like "No Record Found". Right now if the record does not exist Access pops the End/Debug error box up.

Dim dbThisDatabase As DAO.Database
Dim rstGetRecord As DAO.recordset
Dim qdf As DAO.QueryDef

Set dbThisDatabase = CurrentDb
Set qdf = dbThisDatabase.QueryDefs("qryExLoginSelect")
qdf.Parameters("qryParcelID") = Me.[parcel ID]
Set rstGetRecord = qdf.OpenRecordset


The other thing I would like to do is capture the number of records added for the following code.

DoCmd.SetWarnings False
DoCmd.OpenQuery "qryExemptAddRecord"
DoCmd.SetWarnings True

Thanks for any help anyone can provide.

Greg
Hi Greg,

For your first question, after you have opened the recordset you can do the following
Expand|Select|Wrap|Line Numbers
  1.     Set rstGetRecord = qdf.OpenRecordset
  2.     If rsGetRecord.eof then
  3.        'you have no records so do something here
  4.        'Dont forget to close the empty open recordset
  5.    else
  6.        'You have records so do something with them
  7.    end if
  8.  
For your second question, you can use the recordcount property
Expand|Select|Wrap|Line Numbers
  1. rs.RecordCount
but beware, it only counts the records accessed, i.e. it does not hold the correct count until you have ran through the whole recordset.

Another way of doing it is to use DCount. Say qryExemptAddRecord is adding records from tblSomething WHERE xzy conditions apply, you can say
intRecsAdded=dcount("somekey","tblSomething",xyz conditions
Jul 26 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Bilgehan.Balban | last post by:
Hi, Generally in my C code, I use the following convention to return success or failure: a) For functions that return a pointer, (allocation, filling-in a structure etc.) return Null for all...
2
by: Jose | last post by:
There's something for me to learn with this example, i'm sure :) Given this text: "....." and my first attempt at capture the groups: "(?:\)" RegExTest gives me what i expect: 6 captured...
1
by: audipen | last post by:
Hi, I trap the 'OnBuildProjConfigDone' and perform some custom enhancement to the assembly. I check the 'bool Success' parameter before I perform my step. I go ahead only if 'Success == true" ...
5
by: Uma Muthu | last post by:
Hello Everyone, How can I capture the event of closing the IE browser from within an ASP.NET web application? TIA, Uma
4
by: Bill Manring | last post by:
I need to capture the event when the user closes the browser in my application. I have some code in the session_End event, which works fine when the session times out, but I need to end the...
0
by: spam.noam | last post by:
Hello, What is the convention for writing C functions which don't return a value, but can fail? If I understand correctly, 1. PyArg_ParseTuple returns 0 on failure and 1 on success. 2....
0
by: Marc DVer | last post by:
I have a stored procedure that has a simple insert statement. I want to be able to tell if the insert statement executed successfully, and return using a tinyint whether the statement was...
0
by: j101 | last post by:
I am attempting to set up Q Capture on RH Linux (x86_64) using DB2 9 fp2, but there seems to be a general problem loading a specify MQ shared library "/opt/mqm/lib/libmqm_r.so". I have MQ v6...
1
by: pssraju | last post by:
Hi, I am not sure whether I am posting it in right location as i cant see any shell scripting forum here. Below script works perfectly fine from command line, but when I run through browser I am...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.