Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Aссess 2010 database macro

Posted on 2015-02-11
7
Medium Priority
?
152 Views
Last Modified: 2016-02-10
I need to create a macro, that would start after a new record is added to a table. How do I do it?
Also, after the macro is executed, all records from the table should be deleted. Is that possible?
0
Comment
Question by:German Mikulski
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 85
ID: 40602997
2010 includes Data Macros, which can be set to fire AfterInsert, so you could create one that performs whatever task it is you need. I'm not sure you can delete all records from the table in that AfterInsert macro, however.

You could do this on a Form, of course. Using a combination of Form events, you could determine when a New Record is added, and then run your code, and then delete all records in the table.
0
 

Author Comment

by:German Mikulski
ID: 40603181
I have found an After Insert macro in Table Tools, but the list of offered actions there is very limited and does not contain "OpenQuery" - the one which is needed.
In terms of deleting all records, form option will not work, as data is added from a web form directly into the table.
0
 
LVL 85
ID: 40605379
Is this a Web Database?

If so, then you're quite limited in what you can do. Access 2013 moved to Web Apps, which have more functionality, but I don't know if you'll ever be able to do what you want in a Web Database or Web App. Web Databases/Apps are fine for simple CRUD (Create-Read-Update-Delete) actions, but when you get into more complex needs, you often find limitations which prevent you from doing what you want.

You can create a "hybrid" app, where the data resides on Sharepoint/Azure, but your application is a standard, desktop Access database.

If not, then you might be able to create another Macro, and use RunDataMacro action in the AfterInsert table macro.
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:German Mikulski
ID: 40605494
Not, it is just an ordinary .accbd database. I created a separate macro, that would run the needed query. But RunDataMacro shows only data macros, so my macro wasn't displayed. What else can I do?
0
 
LVL 85
ID: 40605550
I'm not sure. I don't really use macros, and haven't for quite some time. From my undestanding, however, Table-based macros (i.e. DataMacros) can only execute other DataMacros. Here's what MSDN has to say about DataMacros:
Data macros are a new feature of Access 2010 which enable you to add logic to events that occur in tables, such as adding, updating, or deleting data. They are similar to "triggers" in Microsoft SQL Server. This article shows you how to create and debug data macros.
From Here: https://support.office.microsoft.com/en-in/article/Create-a-data-macro-b1b94bca-4f17-47ad-a66d-f296ef834200

In other words - I don't think you'll be able to do what you're after, unless you can add code to the web page to handle those actions.
0
 

Author Comment

by:German Mikulski
ID: 40605962
But isn't it possible to write sone kind of vba code that woyld trigger these actions?
0
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 total points
ID: 40625396
If you're doing this from a Form, then you could very likely use VBA to manage this - but that's the only other option if you cannot find a solution using Data Macros (and I don't think you will).

The Form's After Update event, and Before Update event, could be used to do this perhaps. Here's what I'd do:

In the General Declarations section of the form, add this variable:

Dim fIsNew As Boolean

In the Form's Current Event, add this:

fIsNew = Me.NewRecord

Now in the Form's AfterUpdate event, check the value of fIsNew, and take action based on that:

If fIsNew Then
  ' run your macros or vba code

  fIsNew = False
End If
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

719 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