Depending on the data you are entering, you may find that there are times when you just want to copy a piece of data rather than retyping something that you have already typed. If you know how to copy and paste in another Windows application, you probably already know how to do it in Access. Here are the specifics:
- First, select the data you want to copy.
- Press Ctrl-C, click the Copy button, or choose Edit>>Copy from the menu.
- Move the cursor to where you want to copy the data.
- Press Ctrl-V, click the Paste button, or choose Edit>>Paste from the menu. The data will be copied to the new location.
There are three easy ways to complete the cut, copy, and paste actions: you can use the keyboard, the toolbar, or the menu. View the table below to see a quick-reference table.
Action | What it does | Keyboard | Toolbar button | Menu choice |
Cut | Deletes the selected text and stores it on the clipboard | Ctrl-X | | Edit>>Cut |
Copy | Copies the selected text to the clipboard | Ctrl-C | | Edit>>Copy |
Paste | Pastes the contents of the clipboard to the cursors location | Ctrl-V | | Edit>>Paste |
Access 2000 had a new feature that you may not be familiar with, where it allows you to store multiple clips on the clipboard and paste them where you want. This flexibility can be very useful, as you will see. If you are entering repeating data use Ctrl- it repeats the data in the record above for the current field.
Cutting and pasting can be especially useful when you are first building your database, especially if you decide to restructure tables that already have data in them. You can copy more than one cell of data at a time.
I find the easiest way to select a few cells of data is to click at the beginning of the first cell and then Shift-click at the end of the data I want to select. You can also select entire columns or rows by clicking on the row or column header.
And once you have selected the data, you can copy or cut it to the clipboard and copy it to a new location, perhaps even a different table.
The clipboard can be a useful tool for copying data from another application such as Excel or Word. In the next lesson you will learn about
importing data from another application. You may find that you do not need all the bells and whistles offered by the import feature, you can get by simply copying the data you need to the clipboard and then pasting it into an Access table.
Using VBA and type libraries allows you to provide a tremendous amount of flexibility when creating Access 2016 applications. Sometimes, however, you must communicate directly with the operating system of the computer and other components (such as when you manage memory or process or work directly with the user interface elements such as windows or controls, or when modifying the Windows Registry). In these situations, your best option is to use external functions that are embedded in dynamic-link library (DLL) files. You accomplish this in VBA by making API calls using Declare statements. Making API calls is discussed in greater detail in Chapter 9 of this book. Microsoft provides a Win32API.txt file that contains approximately 1,500 Declare statements plus a tool for cutting and pasting the
Declare
statement into your code. Unfortunately, these statements are for 32-bit systems. You will need to convert any of these statements to 64-bit versions before using them in your 64-bit application. Declare statements are used to incorporate API calls into your code. They will take on one of two types:
- subroutine or
- function.
A subroutine cannot provide a return value when called, but a function may provide a return value when called. The following is an example of incorporating an API element of either type:
[Public|Private] Declare [Function|Sub] Name Lib
`` LibraryName Alias `` AliasName _(argument list)
Replace the placeholder (Name) with the actual name of the procedure from the DLL library and replace the placeholder LibraryName with the name of the DLL file that contains the sub or function you wish to incorporate. The Alias argument is optional and allows you to assign your own name to the sub or function for use later in your application. It is useful to use an alias to prevent possible confusion in your code. The (argument list) must contain the parameters and data types that are to be passed to the procedure. Here is an example of incorporating an API function for opening and replacing a subkey in the Windows Registry:
Declare Function RegOpenKeyA Lib
advapi32.dll (ByVal KEY AS Long, ByVal SubKey _As String, NewKey As Long) As Long
In Microsoft Visual C or Visual C++ the previous example will compile correctly for both 32-bit and 64-bit systems. This is because HKey is defined as a pointer and its size directly reflects the platform it is compiled on. Prior versions of VBA, however, do not have a pointer data type so the long data type was used. Because the long data type is always 32-bit, it would break on systems using 64-bit memory space. The upper 32 bits of memory space would either be truncated or would overwrite other memory addresses. This behavior would cause unpredictable results or even system crashes.
In the following
series of images I will show you an easy way to complete a table using the multiple clip feature for cutting and pasting.