dbTalk Databases Forums  

Simple Conditional Macro

comp.databases.ms-access comp.databases.ms-access


Discuss Simple Conditional Macro in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Craig
 
Posts: n/a

Default Simple Conditional Macro - 07-08-2010 , 11:26 AM






I’m trying to make a conditional macro that will check a table to make
sure there isn’t already a record with the same ID and Entry #. If
there is a record, it should give you a message box warning of
duplicate entry. If there isn’t any returned values then it should run
an append query.

So conceptually speaking

If Query1 > 0 then Error Message: “Already entered”
If Query1 Is Null then AppendQuery

Query 1:
(SELECT Count(Tbl_Assessment.ID) AS CountOfID
FROM Tbl_Assessment
WHERE (((Tbl_Assessment.Entry)=1))
GROUP BY Tbl_Assessment. ID, Tbl_Assessment.Entry, [Forms]![Form1]!
[ID]

AppendQuery:
INSERT INTO Tbl_Assment ( Trial, ID )
SELECT Tbl_Lookup.Lookup_Value, [Forms]![Form1]![ID] AS ID
FROM Tbl_Lookup
WHERE (((Tbl_Lookup.Group)=52));

How would I go about doing this in a macro?

Reply With Quote
  #2  
Old   
Salad
 
Posts: n/a

Default Re: Simple Conditional Macro - 07-08-2010 , 12:30 PM






Craig wrote:
Quote:
I’m trying to make a conditional macro that will check a table to make
sure there isn’t already a record with the same ID and Entry #. If
there is a record, it should give you a message box warning of
duplicate entry. If there isn’t any returned values then it should run
an append query.

So conceptually speaking

If Query1 > 0 then Error Message: “Already entered”
If Query1 Is Null then AppendQuery

Query 1:
(SELECT Count(Tbl_Assessment.ID) AS CountOfID
FROM Tbl_Assessment
WHERE (((Tbl_Assessment.Entry)=1))
GROUP BY Tbl_Assessment. ID, Tbl_Assessment.Entry, [Forms]![Form1]!
[ID]

AppendQuery:
INSERT INTO Tbl_Assment ( Trial, ID )
SELECT Tbl_Lookup.Lookup_Value, [Forms]![Form1]![ID] AS ID
FROM Tbl_Lookup
WHERE (((Tbl_Lookup.Group)=52));

How would I go about doing this in a macro?
This link will show you the basics. The queries should be saved if you
used Dcount(). The Dcount() would be on the 1st 2 lines; one to display
the error message, the next to stop the macro. The following lines to
run the append query.
http://www.learnaccessnow.com/chap18c.html

Reply With Quote
  #3  
Old   
Craig
 
Posts: n/a

Default Re: Simple Conditional Macro - 07-08-2010 , 02:18 PM



For anyone who runs across this in the future I was passing the form
values to the DCount function and was having problems it not working.
You need to check the quoting which is explained here:
http://allenbrowne.com/ser-66.html

Reply With Quote
  #4  
Old   
Salad
 
Posts: n/a

Default Re: Simple Conditional Macro - 07-08-2010 , 02:46 PM



Craig wrote:
Quote:
For anyone who runs across this in the future I was passing the form
values to the DCount function and was having problems it not working.
You need to check the quoting which is explained here:
http://allenbrowne.com/ser-66.html

In reality, do you really nead a "group by" query?

All you are really looking for is if there's an Entry = 1 per your query
in the post. In fact, you could create display an error message when a
person enters a 1 into the Entry field.

SELECT EntryID FROM Tbl_Assessment WHERE Entry = 1 would work per the
original post if you didn't want to trap the data entry.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.