Skip to Content
Access 2010: The Missing Manual
book

Access 2010: The Missing Manual

by Matthew MacDonald
June 2010
Intermediate to advanced
834 pages
29h 12m
English
O'Reilly Media, Inc.
Content preview from Access 2010: The Missing Manual

Putting Code in a Form

Running a code routine directly is a bit awkward. At least when you run a macro directly, you can launch it from the navigation pane or use a handy button in the ribbon. Neither option is available with VB code. Instead, you need to open the Visual Basic editor, choose the right module, scroll to the right subroutine, and then click Run. No one actually takes this approach, because it’s just too tedious.

Fortunately, there’s a better approach. You can place code in a form, and then set it to run automatically when something important happens. The following sections explain how.

Responding to a Form Event

Instead of running code routines straight from the editor, Access fans wire them up to form events, just as you can with macros. Here’s how you can try this out:

  1. Open a form in Design mode.

    The fastest way is to right-click a form in the navigation pane, and then choose Design View.

  2. Add a new button.

    To do so, choose Forms Tools | Design→Controls→Button, and then draw the button onto your form.

  3. When the Button wizard begins, press Esc to cancel it.

    You don’t need to create a macro for your button. Instead, this button will be powered by pure VB code.

  4. If the Property Sheet isn’t currently visible, then choose Forms Tools | Design→Tools→Property Sheet.

  5. In the Property Sheet, choose the Other tab, and then set the Name property to give the button a good name.

    Access uses the button name to name the subroutine for your button. It’s much easier to remember what CommitOrder_Click ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Access 2013: The Missing Manual

Access 2013: The Missing Manual

Matthew MacDonald
Microsoft® Access® 2010 24-Hour Trainer

Microsoft® Access® 2010 24-Hour Trainer

Geoffrey L. Griffith, Truitt L. Bradly
Professional Access 2013 Programming

Professional Access 2013 Programming

Teresa Hennig, Ben Clothier, George Hepworth, Dagi Yudovich

Publisher Resources

ISBN: 9781449382384Errata Page