Solved

Microsoft Access, Running custom code when a row is added in a table.

Posted on 2012-03-27
9
166 Views
Last Modified: 2012-04-16
I have a table with a table relationship to a parent table which is a list of items and checkboxes associated with those items, and want to check the parent table and alert me if I try to select an item from the parent table when a specific checkbox is selected in that item's row. How do I do this?
0
Comment
Question by:OAC Technology
  • 4
  • 3
  • 2
9 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 37773900
better upload a copy of your db to avoid too much code posting..
0
 
LVL 2

Author Comment

by:OAC Technology
ID: 37773924
I can't upload my database.
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 37773948
oh well, wait for somebody who have a crystal ball to guess what you have in your db.
0
 
LVL 57
ID: 37774001
cap,

<<oh well, wait for somebody who have a crystal ball to guess what you have in your db.>>

  That's not a helpful comment.

DataDudes,

  Not quite clear on what it is your trying to do exactly.  JET/ACE does not have table level triggers unless you use 2010 and a macro.

 In general, checking is done in a BeforeUpdate event of a form.  This is the event that occurs just before a record is written out.  It is a cancelable event, so you can stop the save if something is going on that you don't like.

AfterUpdate occurs after the current record has been saved, and this is your shot to do something accordingly.

 If that doesn't get you going, outline in a little more detail what the situation is.

Jim.
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 2

Author Comment

by:OAC Technology
ID: 37774103
Ok, I figured out how to make a dialog box pop up in the form, and it cancels properly.
I have a table called "Company", with a column called "Company", and a check box column which is called "ON HOLD". If the "ON HOLD" check box for a Company is selected, I want the dialog box to pop up.
The form I'm working with is linked to a different table, with a relationship to the Company table to get its data.
0
 
LVL 57
ID: 37774685
<< I want the dialog box to pop up.>>

 When?

Jim.
0
 
LVL 2

Author Comment

by:OAC Technology
ID: 37777467
As soon as a company with the check box checked is selected.
Table 1 looks like this:
---------------------------------
|Company | On Hold |
===================
|   name     | checked |
---------------------------------

Table 2 is different, but it references Table 1 to get the Company names. If the check box in Table 1 is checked I want to get the message box. My form created off of Table 2.
0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 37778688
If I'm understanding you correctly, the event you would want is OnCurrent.  OnCurrent fires whenever a new record gets the focus.

As for the check, you could use Dlookup() to return the field or open a recordset to find the record in table 1 and get the field value.

Some other events that might be helpful:

BeforeInsert - Occurs when you press a key in the new record, but before the record is actually created.

AfterInsert - Occurs after the new record has been added.  

 Note that the order of events on a new record are:

BeforeInsert > BeforeUpdate > AfterUpdate > AfterInsert


  and yes, that's correct, AfterInsert occurs after  the AfterUpdate event.

Jim.
0
 
LVL 57
ID: 37778699
One thing that's always good to do when your not sure what event to use is keep a spare form bound to a simple table.  In each event, put a STOP, message box, or print to the debug window something like "just hit afterupdate".

Then do the operation your trying to do and look at what you hit or see in the debug window.

 Doing that with reports is a real eye opener!

Jim.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

896 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now