Instant Microsoft Access 2013 Programming by Example with VBA XML and ASP 1st Edition Julitta Korol ebook download PDF full chapters
Instant Microsoft Access 2013 Programming by Example with VBA XML and ASP 1st Edition Julitta Korol ebook download PDF full chapters
https://ebookultra.com/download/xml-programming-web-applications-and-
web-services-with-jsp-and-asp-1st-edition-alexander-nakhimovsky/
https://ebookultra.com/download/microsoft-access-2013-illustrated-
brief-1st-edition-lisa-friedrichsen/
https://ebookultra.com/download/access-2007-vba-programming-for-
dummies-1st-edition-joseph-c-stockman/
https://ebookultra.com/download/applied-xml-programming-for-microsoft-
net-1st-edition-dino-esposito/
Korn shell programming by example 1st Edition Dennis
O'Brien
https://ebookultra.com/download/korn-shell-programming-by-example-1st-
edition-dennis-obrien/
https://ebookultra.com/download/programming-language-fundamentals-by-
example-1st-edition-d-e-stevenson/
https://ebookultra.com/download/access-2007-vba-bible-for-data-
centric-microsoft-office-applications-1st-edition-helen-feddema/
https://ebookultra.com/download/excel-programming-with-vba-
starter-1st-edition-robert-martin/
https://ebookultra.com/download/cocoon-2-programming-web-publishing-
with-xml-and-java-1st-edition-bill-brogden/
Microsoft Access 2013 Programming by Example with
VBA XML and ASP 1st Edition Julitta Korol Digital
Instant Download
Author(s): Julitta Korol
ISBN(s): 9781938549496, 193854949X
Edition: 1
File Details: PDF, 56.58 MB
Year: 2014
Language: english
MICROSOFT® ACCESS® 2013
PROGRAMMING BY EXAMPLE
LICENSE, DISCLAIMER OF LIABILITY, AND LIMITED WARRANTY
By purchasing or using this book (the “Work”), you agree that this license
grants permission to use the contents contained herein, but does not give you
the right of ownership to any of the textual content in the book or ownership
to any of the information or products contained in it. This license does not
permit uploading of the Work onto the Internet or on a network (of any kind)
without the written consent of the Publisher. Duplication or dissemination
of any text, code, simulations, images, etc. contained herein is limited to and
subject to licensing terms for the respective products, and permission must
be obtained from the Publisher or the owner of the content, etc., in order to
reproduce or network any portion of the textual material (in any media) that is
contained in the Work.
MERCURY LEARNING AND INFORMATION LLC (“MLI” or “the Publisher”) and anyone
involved in the creation, writing, or production of the companion disc, accom-
panying algorithms, code, or computer programs (“the software”), and any
accompanying Web site or software of the Work, cannot and do not warrant
the performance or results that might be obtained by using the contents of the
Work. The author, developers, and the Publisher have used their best efforts to
insure the accuracy and functionality of the textual material and/or programs
contained in this package; we, however, make no warranty of any kind, express
or implied, regarding the performance of these contents or programs. The
Work is sold “as is” without warranty (except for defective materials used in
manufacturing the book or due to faulty workmanship).
The author, developers, and the publisher of any accompanying content, and
anyone involved in the composition, production, and manufacturing of this
work will not be liable for damages of any kind arising out of the use of (or the
inability to use) the algorithms, source code, computer programs, or textual
material contained in this publication. This includes, but is not limited to, loss
of revenue or profit, or other incidental, physical, or consequential damages
arising out of the use of this Work.
The sole remedy in the event of a claim of any kind is expressly limited to
replacement of the book, and only at the discretion of the Publisher. The use
of “implied warranty” and certain “exclusions” vary from state to state, and
might not apply to the purchaser of this product.
MICROSOFT® ACCESS® 2013
PROGRAMMING BY EXAMPLE
with VBA, XML, and ASP
Julitta Korol
This publication, portions of it, or any accompanying software may not be reproduced in any
way, stored in a retrieval system of any type, or transmitted by any means, media, electronic display
or mechanical display, including, but not limited to, photocopy, recording, Internet postings, or
scanning, without prior permission in writing from the publisher.
Julitta Korol. Microsoft Access 2013 Programming by Example with VBA, XML, and ASP.
ISBN: 978-1-938549-80-9
The publisher recognizes and respects all marks used by companies, manufacturers, and
developers as a means to distinguish their products. All brand names and product names
mentioned in this book are trademarks or service marks of their respective companies. Any
omission or misuse (of any kind) of service marks or trademarks, etc. is not an attempt to
infringe on the property of others.
141516321
Our titles are available for adoption, license, or bulk purchase by institutions, corporations, etc.
For additional information, please contact the Customer Service Dept. at 1-800-758-3756 (toll free).
The sole obligation of Mercury Learning and Information to the purchaser is to replace the
disc, based on defective materials or faulty workmanship, but not based on the operation or
functionality of the product.
To my husband, Paul, and my parents-in-law, Alfreda and Piotr Korol.
They’ve been my biggest fans since the first edition of this book.
I am thankful for their love and support.
CONTENTS
Dedication .................................................................................................... v
Acknowledgments ..................................................................................... xxv
Introduction ............................................................................................ xxvii
User-Level Security.....................................................................................587
Understanding Workgroup Information Files ............................................587
Creating and Joining Workgroup Information Files..............................590
Opening a Secured MDB Database ..............................................................596
Creating and Managing Group and User Accounts....................................599
Deleting User and Group Accounts .........................................................603
Listing User and Group Accounts ............................................................605
Listing Users in Groups .............................................................................606
Setting and Retrieving User and Group Permissions .................................608
Determining the Object Owner................................................................608
Setting User Permissions for an Object ...................................................611
Setting User Permissions for a Database .................................................614
Setting User Permissions for Containers .................................................616
Checking Permissions for Objects............................................................618
Setting a Database Password Using the
CompactDatabase Method ...............................................................621
Setting a Database Password Using the
NewPassword Method.......................................................................622
Changing a User Password ........................................................................624
Encrypting a Secured MDB Database ..........................................................626
Chapter Summary ...........................................................................................628
Activate ........................................................................................................787
Deactivate ....................................................................................................788
NoData .........................................................................................................788
Page...............................................................................................................789
Error .............................................................................................................790
Events Recognized by Report Sections .........................................................792
Format (Report Section Event) .................................................................792
Print (Report Section Event) .....................................................................795
Retreat (Report Section Event) .................................................................799
Using the Report View ....................................................................................799
Sorting and Grouping Data ............................................................................801
Saving Reports in .pdf or .xps File Format...................................................802
Using the OpenArgs Property of the Report Object ..................................803
Chapter Summary ...........................................................................................806
Index ..............................................................................................1093
ACKNOWLEDGMENTS
F
irst, I’d like to express my gratitude to everyone at Mercury Learning and
Information. A sincere thank-you to my publisher, David Pallai, for offering
me the opportunity to update this book to the new 2013 version and tire-
lessly keeping things on track during this long project.
A whole bunch of thanks go to the editorial team for working so hard to bring this
book to print. In particular, I would like to thank the copyeditor, Tracey McCrea, for
the thorough review of my writing. To Jennifer Blaney, for her production expertise
and keeping track of all the edits and file processing issues. To the compositor,
L. Swaminathan at SwaRadha Typesetting, for all the typesetting efforts that gave
this book the right look and feel.
Special thanks to my husband, Paul, for his patience during this long project
and having to put up with frequent take out dinners.
Finally, I’d like to acknowledge readers like you who cared enough to post
reviews of the previous edition of this book online. Your invaluable feedback has
helped me raise the quality of this work by including the material that matters to
you most. Please continue to inspire me with your ideas and suggestions.
xxv
INTRODUCTION
F
or many years now, Microsoft Access has allowed users to design and de-
velop Windows-based database applications, and Access continues to be the
world’s most popular database. This book is for people who have already
mastered the use of Microsoft® Access® databases and now are ready for the next
step — programming. Microsoft Access 2013 Programming by Example with VBA,
XML, and ASP takes nonprogrammers through detailed steps of creating Access
databases from scratch and shows them how to retrieve and manage their data
programmatically using various programming languages and techniques. With this
book in hand, users can quickly build the toolset required for developing their own
database solutions. With this book’s approach, programming an Access database
from scratch and controlling it via programming code is as easy as designing and
maintaining databases with the built-in tools of Access. This book gives a practical
overview of many programming languages and techniques necessary in program-
ming, maintaining, and retrieving data from today’s Access databases.
PREREQUISITES
You don’t need any programming experience to use Microsoft Access 2013 Pro-
gramming by Example with VBA, XML, and ASP. The only prerequisite is that you
already know how to manually design an Access database and perform database
tasks by creating and running various types of queries. This book also assumes that
you know how to create more complex forms with embedded subforms, combo
boxes, and other built-in controls. If you don’t have these skills, there are countless
books on the market that can teach you step by step how to build simple databases.
If you do meet these criteria, this book will take you to the Access programming
level by example. You will gain working knowledge immediately by performing
xxvii
xxviii INTRODUCTION
concrete tasks and without having to read long descriptions of concepts. True
learning by example begins with the first step, followed by the next step, and the
next one, and so on. By the time you complete all of the steps in a hands-on exer-
cise or a custom project, you should be able to effectively apply the same technique
again and again in your own database projects.
This book is divided into nine parts (a total of 32 chapters) that progressively in-
troduce you to programming Access databases.
Part I introduces you to Access 2013 VBA programming. Visual Basic for Ap-
plications (VBA) is the programming language for Microsoft Access. In this part
of the book, you acquire the fundamentals of VBA that you will use over and over
again in building real-life Access database applications.
The skills obtained in Parts I, II, III, and IV are fairly portable. They can be
utilized in programming other Microsoft Office applications that also use VBA as
their native programming language such as Excel, Word, PowerPoint, Outlook, and
so on.
Part V introduces you to two sets of programming objects known as Data Ac-
cess Objects (DAO) and ActiveX Data Objects (ADO) that enable Microsoft Access
and other client applications to access and manipulate data. In this part of the book,
you learn how to use DAO and ADO objects in your VBA code to connect to a data
source; create, modify, and secure database objects.
This book has been designed as a tutorial and should be followed chapter by chapter.
As you read each chapter, perform the tasks that are described. Be an active
learner by getting involved in the book’s hands-on exercises and custom projects.
When you are completely involved, you learn things by doing rather than studying,
and you learn faster. Do not move on to new information until you’ve fully grasped
the current topic. Allow your brain to sort things out and put them in proper per-
spective before you move on. Take frequent breaks between your learning sessions,
as some chapters in this book cover lots of material. Do not try to do everything in
one sitting. It’s always better to divide the material into smaller units than attempt
to master all there is to learn at once. However, never stop in the middle of a hands-
on exercise; finish it before taking a break. After learning a particular technique or
command, try to think of ways to apply it to your own work. As you work with this
book, create small sample procedures for yourself based on what you’ve learned
up to a particular point. These procedures will come in handy when you need to
review the subject in the future or simply need to steal some ready-made code.
The example files for all the hands-on activities in this book are available on the
CD-ROM disc included with this book.
INTRODUCTION TO
P a rt 1 ACCESS 2013 VBA
PROGRAMMING
V
isual Basic® for Applications (VBA) is the programming language for
Microsoft® Access®. In this part of the book, you acquire the fundamen-
tals of VBA that you will use over and over again in building real-life
Microsoft Access database applications.
1
WRITING
Ch ap t er 1 PROCEDURES IN
MODULES
T
his chapter’s objective is to introduce you to writing programming code
using the built-in language of Microsoft Access—Visual Basic for Appli-
cations (commonly referred to as VBA). By writing your own code you
can extend the functionality of existing Microsoft Access database applications
or create your own applications from scratch. VBA is a language embedded in
all the Microsoft Office applications. Therefore, what you learn in this book
about Access programming can be utilized in writing programs that control
Excel®, Word®, Outlook®, or Project. Your job as a programmer (at least dur-
ing the course of this book) will boil down to writing various procedures. A
procedure is a group of instructions that allows you to accomplish specific tasks
when your program runs. When you place instructions (programming code)
in a procedure, you can call this procedure whenever you need to perform that
particular task. Although many tasks can be automated in Access 2013 by using
macro actions, such as opening forms and reports, finding records, and execut-
ing queries, you will need VBA skills to perform advanced customizations in
your desktop databases.
3
4 M ICROSOFT A CCESS 2013 PROGRAMMING
PROCEDURE TYPES
VBA has the following types of procedures: subroutine procedures, function
procedures, event procedures, and property procedures. You create and store
procedures in modules. Each procedure in the same module must have a unique
name; however, procedures in different modules can have the same name. Let’s
learn a bit about each procedure type so that you can quickly recognize them
when you see them in books, magazine articles, or online.
1. Subroutine procedures (also called subroutines or subprocedures)
Subroutine procedures perform useful tasks but never return values. They be-
gin with the keyword Sub and end with the keywords End Sub. Keywords are
words that carry a special meaning in VBA. Let’s look at the simple subroutine
ShowMessage that displays a message to the user:
Sub ShowMessage()
MsgBox "This is a message box in VBA."
End Sub
Notice a pair of empty parentheses after the procedure name. The instruction
that the procedure needs to execute is placed on a separate line between the Sub
and End Sub keywords. You may place one or more instructions and even com-
plex control structures within a subroutine procedure. Instructions are also
called statements. The ShowMessage procedure will always display the same
message when executed. MsgBox is a built-in VBA function often used for pro-
gramming user interactions (see Chapter 4, "Passing Arguments to Procedures
and Functions," for more information on this function). To execute the preced-
ing subroutine programmatically, you need to write the following line of code:
Call ShowMessage()
The Call statement followed by the procedure name tells VBA to execute the
instructions contained within the named procedure. If you’d like to write a
more universal procedure that can display a different message each time the
procedure is executed, you will need to write a subroutine that takes argu-
ments. Arguments are values that are needed for a procedure to do something.
Arguments are placed within the parentheses after the procedure name. Let’s
look at the following procedure that also displays a message to the user; how-
ever, this time we can pass any text string to display:
Sub ShowMessage2(strMessage)
MsgBox strMessage
End Sub
WRITING PROCEDURES IN M ODULES 5
This subprocedure requires one text value before it can be run; strMessage is
the arbitrary argument name. It can represent any text you want. Therefore, if
you pass it the text "Today is Monday," that is the text the user will see when the
procedure is executed. If you don’t pass the value to this procedure, VBA will
display an error.
If your subprocedure requires more than one argument, list the arguments
within the parentheses and separate them with commas. For example, let’s im-
prove the preceding procedure by passing it also a text string containing a user
name:
Sub ShowMessage3(strMessage, strUserName)
MsgBox strUserName & ", your message is: " & strMessage
End Sub
The ampersand (&) operator is used for concatenating text strings inside the
VBA procedure. If we pass to the above subroutine the text "Keep on learning."
as the strMessage argument and "John" as the strUserName argument, the pro-
cedure will display the following text in a message box:
John, your message is: Keep on learning.
To call this subroutine from another procedure, you can write the following
line of code:
Call ShowMessage3("Keep on learning.", "John")
Notice that when calling a procedure with arguments, the arguments are en-
closed in parentheses. The arguments are listed in the same order in which they
are specified in the procedure definition. See exceptions to this rule and dis-
cover more information about passing arguments to subprocedures and func-
tions in Chapter 4.
2. Function procedures (functions)
Functions perform specific tasks and can return values. They begin with the
keyword Function and end with the keywords End Function. Let’s look at a
simple function that adds two numbers:
Function addTwoNumbers()
Dim num1 As Integer
Dim num2 As Integer
num1 = 3
num2 = 2
addTwoNumbers = num1 + num2
End Function
6 M ICROSOFT A CCESS 2013 PROGRAMMING
The preceding function procedure always returns the same result, which is the
value 5. The Dim statements inside this function procedure are used to declare
variables that the function will use. A variable is a name that is used to refer
to an item of data. Because we want the function to perform a calculation, we
specify that the variables will hold integer values. Variables and data types used
in Access 2013 are covered in detail in Chapter 3, "Using Variables, Data Types,
and Constants."
The variable definitions (the lines with the Dim statements) are followed
by the variable assignment statements in which we assign specific numbers to
the variables num1 and num2. Finally, the calculation is performed by adding
together the values held in both variables: num1 + num2. To return the result
of our calculation, we set the function name to the value or the expression we
want to return:
addTwoNumbers = num1 + num2
Although this function example returns a value, not all functions have to return
values. Functions, like subroutines, can perform a number of actions without
returning any values.
Similar to procedures, functions can accept arguments. For example, to make
our addTwoNumbers function more versatile, we can rewrite it as follows:
Function addTwoNumbers2(num1 As Integer, num2 As Integer)
addTwoNumbers2 = num1 + num2
End Function
Now we can pass any two numbers to the preceding function to add them to-
gether. For example, we can write the following statement to display the result
of the function in a message box:
MsgBox("Total=" & addTwoNumbers2(34,80))
You will learn more about writing and calling functions in Chapter 4.
3. Event procedures
Event procedures are automatically executed in response to an event initiated
by the user or program code, or triggered by the system. Events, event proper-
ties, and event procedures are introduced later in this chapter. They are also
covered in Part IV, "Error Handling and Debugging."
4. Property procedures
Property procedures are used to get or set the values of custom properties
for forms, reports, and class modules. The three types of property proce-
dures (Property Get, Property Let, and Property Set) begin with the Property
WRITING PROCEDURES IN M ODULES 7
keyword followed by the property type (Get, Let, or Set), the property name,
and a pair of empty parentheses, and end with the End Property keywords.
Here’s an example of a property procedure that retrieves the value of an author’s
royalty:
Property Get Royalty()
Royalty = (Sales * Percent) – Advance
End Property
MODULE TYPES
As mentioned earlier, procedures are created and stored in modules. Like the
previous version, Access 2013 has two types of modules: standard and class.
Standard Modules
Standard modules are used to hold subprocedures and function procedures that
can be run from anywhere in the application because they are not associated
with any particular form or report.
Please note files for the "Hands-On" project may be found on the companion
CD-ROM.
4. Insert a standard module by choosing Module from the Insert menu (see
Figure 1.3).
Each module begins with a declaration section that lists various settings and
declarations that apply to every procedure in the module. Figure 1.4 shows the
default declaration. Option Compare specifies how string comparisons are eval-
uated in the module—whether the comparison is case sensitive or insensitive.
This is a case-insensitive comparison that respects the sort order of the data-
base. This means that "a" is the same as "A." If you delete the Option Compare
Database statement, the default string comparison setting for the module is
Option Compare Binary (used for case-sensitive comparisons where "a" is not
the same as "A").
Another declaration (not shown here), the Option Explicit statement is of-
ten used to ensure that all variable used within this module are formally de-
clared. You will learn more about this statement and variables in Chapter 4.
Following the declaration section is the procedure section, which holds the
module’s procedures. You can begin writing your procedures at the cursor po-
sition within the Module1 (Code) window.
5. In the Module1 (Code) window, enter the code of subroutines and function
procedures as shown in Figure 1.5.
Notice that Access inserts a horizontal line after each End Sub or End Function
keyword to make it easier to identify each procedure. The Procedure drop-
down box at the top-right corner of the Module1(Code) window displays the
name of the procedure in which the insertion point is currently located.
10 M ICROSOFT A CCESS 2013 PROGRAMMING
the Access window seems stuck and you can’t activate any menu option, this is
often an indication that there is a message box open in the background. Access
will not permit you to do any operation until you close the pop-up window.
3. Now, run this procedure for the third time by clicking the Run Sub/UserForm
button ( ) on the toolbar. This button has the same tool tip as the Run Sub/
UserForm (F5) option on the Run menu.
Procedures that require arguments cannot be executed directly using
the methods you just learned. You need to type some input values
for these procedures to run. A perfect place to do this is the Immedi-
ate window, which is covered in detail in Chapter 2, "Exploring the
Visual Basic Editor (VBE)." For now, let’s open this window and see
how you can use it to run VBA procedures.
4. Select Immediate Window from the View menu.
Access opens a small window and places it just below the Module1 (Code)
window. You can size and reposition this window as needed. Figure 1.6 shows
statements that you will run from the Immediate window in Steps 5–8.
5. Type the following in the Immediate window and press Enter to execute.
ShowMessage2 "I’m learning VBA."
Access executes the procedure and displays the message in a message box. Click
OK to close the message box. Notice that to execute the ShowMessage2 pro-
cedure, you need to type the procedure name, a space, and the text you want
to display. The text string must be surrounded by double quotation marks.
In a similar way you can execute the ShowMessage3 procedure by providing
two required text strings. For example, on a new line in the Immediate window,
type the following statement and press Enter to execute:
ShowMessage3 "Keep on learning.", "John"
When you press the Enter key, Access executes the ShowMessage3 procedure
and displays the text "John, your message is: Keep on learning." Click OK to
close this message box.
You can also use the Call statement to run a procedure in the Imme-
diate window. When using this statement you must place the values
of arguments within parentheses, as shown here:
Call ShowMessage3("Keep on learning.", "John")
Note 16: Il est clair, par exemple, que les Spartiates n'étaient
essentiellement, pour ainsi dire, que des Romains avortés, faute
d'un milieu convenable, admirablement organisés pour la guerre,
et ne pouvant néanmoins conquérir avec fruit. Mais cette
peuplade n'en a pas moins rempli une indispensable fonction dans
le système total de la civilisation grecque, comme propre à
constituer le principal noyau militaire, dans les occasions capitales
où la Grèce devait agir, et surtout résister, collectivement; quoique
son aveugle antipathie contre Athènes l'ait trop souvent conduite,
en ses temps même de plus grande splendeur, à seconder
honteusement les projets hostiles de la théocratie persane, qu'elle
avait, en d'autres cas, si noblement combattue.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookultra.com