Microsoft Office Tutorials and References
In Depth Information
Discovering Code As You Go
Suppose that you come across some code on a web page that you want to
use in your own database. Here’s what to do:
1. On the web page, drag the mouse pointer through the code you want
to copy to select it; then press Ctrl+C to copy the selected code to the
2. Back in Access, create a new module or open the existing module in
which you want to place the code.
3. In the Code window, click where you want to put the copied code.
4. Paste the code at the cursor position by pressing Ctrl+V.
Bear in mind that just pasting code into the Code window doesn’t make the
code do anything. Most code examples are based on a sample database.
Just dropping an example into your database may not be enough to get it to
When you copy and paste from a web page, you may get some HTML tags,
weird characters, weird spacing, and so on. If that happens, you can copy
the code from the page and paste it into a simple text editor like Notepad
first. That method should get rid of any unusual tags and characters. Then
copy and paste the text from the Notepad document into VBE’s Code
Even if you do find an example that’s generic enough to work in any
database, however, the code won’t actually do anything until some event in your
database triggers it. In Book VIII, Chapter 2, we look at the many ways that
you can trigger code.