No Records Deleted Message

M

Micki

I have a macro that runs a delete query that only deletes records if matching
records do not exists in another table. The delete query is working fine,
but I would like a message box to appear if the delete fails due to the
matching records.

My query is [Delete Weld] and the key field is [Weld Number].

I have created a error message form and added the OpenForm command to the
macro with the condition [Delete Weld].[Weld Number] Is Null but the form
opens regardless of whether records are deleted or not.

Any suggestions?
 
M

MGFoster

Micki said:
I have a macro that runs a delete query that only deletes records if matching
records do not exists in another table. The delete query is working fine,
but I would like a message box to appear if the delete fails due to the
matching records.

My query is [Delete Weld] and the key field is [Weld Number].

I have created a error message form and added the OpenForm command to the
macro with the condition [Delete Weld].[Weld Number] Is Null but the form
opens regardless of whether records are deleted or not.

Any suggestions?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You can't use a macro to get what you want. You have to use VBA and the
RecordsAffected property. You could set up the macro to run the VBA by
putting the function in a standard module and using the macro Run Code
option.

Public Function RunQuery(strQuery As String) As Long

' strQuery = name of query to run

On Error Goto err_

dim db as DAO.database, qd as DAO.querydef

set db = currentdb
set qd = db.querydefs(strquery)

with qd
.execute dbfailonerror
RunQuery = .RecordsAffected
end with

qd.close : set qd = nothing
db.close : set db = nothing
exit function

' set up an error handler here
err_:

End Function

In the macro's Function Name field put RunQuery(query_name). Substitute
your query's name for "query_name."

HTH,
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBSjqvxYechKqOuFEgEQITMwCeOw1OlgdEl2TzoTe/s7f9xoCz61kAmwVq
DiCZPp5aMCIOZ8pY/XOLpo8Y
=1dv1
-----END PGP SIGNATURE-----
 
K

Klatuu

Before you execute the query, use a DCount function to see if there are any
matching records.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top