Cheat Sheet

Access 2007 VBA Programming For Dummies

From Access 2007 VBA Programming For Dummies by Joseph C. Stockman, Alan Simpson

Using VBA (Visual Basic for Application) to program Microsoft Access 2007 is simplified if you use shortcuts for debugging code in VBA and perform common tasks in VBA editor and the VBA immediate and code windows. Also, consider learning the codes used for completing common VBA jobs.

Common Shortcuts in VBA-Access 2007

Knowing the most popular keyboard shortcuts in VBA-Access 2007 will help you work more efficiently. Use this shortcut chart until you learn the keyboard combinations and their functions:

To Do This Press This
Switch between Access and the VBA editor Alt+F11
Get help F1
View Object Browser (VBA Editor) F2
View properties and events F4
Close VBA Editor and return to Access Alt+Q

Shortcut Keys to Debug Code in VBA 2007

Avoiding bugs or errors means you have to be precise when writing code in a programming language. Luckily, using these shortcuts will debug code quickly in VBA:

Action Shortcut Key
Toggle breakpoint F9
Step into F8
Step over Shift+F8
Step out Ctrl+Shift+F8
Run to cursor Ctrl+F8
Clear all breakpoints Ctrl+F9

Common Shortcut Keys in VBA 2007 Editor

Writing, editing, and testing your VBA code in Visual Basic editor will run more smoothly if you learn these helpful shortcut keys and their functions:

Action Shortcut Key
Get help F1
View Object Browser F2
View properties F4
View Code window F7
Open Project Explorer Ctrl+R
Close and return to Access Alt+Q
Switch to Access Alt+F11
View Immediate window Ctrl+G
View shortcut menu Shift+F10 (or right-click)
View definition Shift+F2
Go to last position Ctrl+Shift+F2
Run a Sub/UserForm F5
Stop code execution Ctrl+Break

VBA 2007 Shortcuts for Immediate and Code Windows

To get your tasks done quickly in the Immediate window (which lets you run code anytime, right on the spot) and Code window (used for writing, editing, and viewing VBA) use these VBA shortcuts:

Action Shortcut Key
Move cursor right one character -→
Select character to right Shift+-→
Move cursor right one word Ctrl+-→
Select to end of word Ctrl+Shift+-→
Move cursor left one character <---
Select character to left of cursor Shift+<---
Move cursor left one word Ctrl+<---
Move cursor to start of line Home
Select text to start of line Shift+Home
Move cursor to end of line End
Select text to end of line Shift+End
Move cursor up a line
Move cursor down a line
Move cursor to next procedure Ctrl+↓
Move cursor to previous procedure Ctrl+↑
Scroll up one screen PgUp
Scroll down one screen PgDn
Go to top of module Ctrl+Home
Select all text to top of module Ctrl+Shift+Home
Go to bottom of module Ctrl+End
Select all text to bottom of module Ctrl+Shift+End
Cut selection Ctrl+X
Copy selection Ctrl+C
Paste selection Ctrl+V
Cut current line to Clipboard Ctrl+Y
Delete to end of word Ctrl+Delete
Delete character or selected text Delete (Del)
Delete character to left of cursor Backspace
Delete to beginning of word Ctrl+Backspace
Undo Ctrl+Z
Indent line Tab
Outdent line Shift+Tab
Find Ctrl+F
Replace Ctrl+H
Find Next F3
Find Previous Shift+F3
Get help with selected word F1
Get Quick Info Ctrl+I

Codes for Common VBA 2007 Tasks

This list shows you the most common jobs carried out in VBA 2007 and the code statements you need to type to complete the VBA task, so keep this list handy:

Open a form in Form view:

DoCmd.OpenForm "formname", acNormal

Change a form property on an open form:

Forms![formName].propertyName = newValue

Get value from a control on an open form:

Forms![formName]![controlName].Value

Change value of a control on an open form:

Forms![formName]![controlName].Value = newValue

Change a control property on an open form:

Forms![formName]![controlName].propertyName = newValue

Close a form, saving design changes:

DoCmd.Close acForm, "formName", acSaveYes

Print a report:

DoCmd.OpenReport "reportName", acViewNormal

Run an action query:

DoCmd.RunSQL "SQLstatement"

Show a simple message:

MsgBox "yourMessage"

Ask a question on-screen:

variable = MsgBox("yourMessage", vbQuestion + vbYesNo)
  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
Advertisement

Inside Dummies.com

Dummies.com Sweepstakes

Win $500. Easy.