Append query if criteria is not met

  • Thread starter Thread starter wesley.allen
  • Start date Start date
W

wesley.allen

Hello.

I am trying to run an append query that will append a record to a
table if a certain criteria is not met.

When my database opens, I want it to look to a table and see if there
is a record for today's date. If not, I want it to add one. If a
record already exists, I want it to do nothing.

I have tried running append queries, queries based on other queries,
etc. I can't get anything to work.

Any ideas?

Thanks
 
You just need to do an SQL INSERT e.g.

Dim strSQL As string
strSQL = "INSERT INTO MyTableName (Field1,Field2) VALUES('ABC','XYZ')"
CurrentProject.Connection.Execute strSQL


-Dorian
 
Kind of hard to say since you don't describe what the certain criteia is.
For that matter, you don't say if the criteria for running the query is even
in the same table.
What you want M I G H T be

INSERT Into SomeTable (Field1, Field2, Field3)
Values ("A", 2, Date())
WHERE Not Exists (SELECT * FROM SomeTable WHERE Field3 = Date())

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
I apologize. I was trying to keep it simple. I am not sure exactly
how to modify your suggestion, so I will give details and see if you
can help.

I have a query that calculates a bank balance. I want this query to
append the current days date and the bank balance to a table. I have
a macro setup to autorun the query when my database opens, but can't
get it to work correctly. Details:

Table where I want the records added: BankingBalanceRecord
Query that will run: BankingRecordBalance
-This query is setup to pull
today's date and the balance. It is funtioning properly.

The main problem I am having is that if the primary record (Today's
date) already exists, it gives me an error message. As I open the
database multiple times a day, i only want it to record the balance
the first time.

Thanks for the help.
 

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

Back
Top