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.






>


>


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.



































































































































































ActionShortcut Key
Move cursor right one character
Select character to rightShift+→
Move cursor right one wordCtrl+→
Select to end of wordCtrl+ Shift+→
Move cursor left one character
Select character to left of cursorShift+←
Move cursor left one wordCtrl+←
Move cursor to start of lineHome
Select text to start of lineShift+Home
Move cursor to end of lineEnd
Select text to end of lineShift+End
Move cursor up a line
Move cursor down a line
Move cursor to next procedureCtrl+↓
Move cursor to previous procedureCtrl+↑
Scroll up one screenPgUp
Scroll down one screenPgDn
Go to top of moduleCtrl+Home
Select all text to top of moduleCtrl+ Shift+Home
Go to bottom of moduleCtrl+End
Select all text to bottom of moduleCtrl+ Shift+End
Cut selectionCtrl+X
Copy selectionCtrl+C
Paste selectionCtrl+V
Cut current line to ClipboardCtrl+Y
Delete to end of wordCtrl+Delete
Delete character or selected textDelete (Del)
Delete character to left of cursorBackspace
Delete to end of wordCtrl+Delete
Delete to beginning of wordCtrl+Backspace
UndoCtrl+Z
Indent lineTab
Outdent lineShift+Tab
FindCtrl+F
ReplaceCtrl+H
Find NextF3
Find PreviousShift+F3
Get help with currently selected wordF1
Quick InfoCtrl+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.















































ActionShortcut Key
Switch between Access and the VBA editorAlt+F11
HelpF1
View Object BrowserF2
View properties/eventsF4
View Code windowF7
View Immediate windowCtrl+G
View shortcut menuShift+F10 (or right-click)
Run a Sub/UserFormF5
Stop code executionCtrl+Break
Close VBA Editor and return to AccessAlt+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:































ActionShortcut Key
Toggle breakpointF9
Step intoF8
Step overShift+F8
Step outCtrl+Shift+F8
Run to cursorCtrl+F8
Clear all breakpointsCtrl+F9




>






>
dummies


Source:http://www.dummies.com/how-to/content/access-vba-programming-for-dummies.html

No comments:

Post a Comment