Access VBA Programming For Dummies

Programming Microsoft Access with VBA can be a lot easier if you know the keyboard shortcuts for the most common commands and tasks and the most common bits of code that you’ll use in the editor and immediate windows as you build and debug your Access application.

Access VBA Programming For Dummies

Common Code for VBA Programming and Debugging in Access

This list which shows you the most common jobs performed in VBA and the statements you need to type to get the VBA task completed, 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 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 yes/no question onscreen:

variable = MsgBox("yourMessage", vbQuestion + vbYesNo)

Navigating and Selecting Code in VBA

Use these VBA shortcuts in the Code window (used for writing, editing, and viewing VBA) and the Immediate window (which lets you run code any time, right on the spot) to get your jobs done quickly.

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 end of word Ctrl+Delete
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 currently selected word F1
Quick Info Ctrl+I

General VBA Editor Shortcut Keys

The following table shows you some helpful shortcut keys, and their functions, available throughout the Visual Basic editor, where you write, edit, and test your VBA code.

Action Shortcut Key
Switch between Access and the VBA editor Alt+F11
Help F1
View Object Browser F2
View properties/events F4
View Code window F7
View Immediate window Ctrl+G
View shortcut menu Shift+F10 (or right-click)
Run a Sub/UserForm F5
Stop code execution Ctrl+Break
Close VBA Editor and return to Access Alt+Q

VBA Debugging Shortcut Keys

Since code in a programming language has to be written exactly, there can be no errors or bugs. Fortunately, you can debug code in VBA quickly with these debugging shortcuts:

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

By Alan Simpson