Skip to main content

Beginning Access 2000 VBA

Beginning Access 2000 VBA

Robert Smith, Dave Sussman

ISBN: 978-0-764-54383-8

Apr 2000

896 pages

Select type: Paperback

Product not available for purchase

Description

What is this book about?

Access 2000 is an important part of the Office 2000 program suite, and is available on both the Premium and Professional editions of Office 2000. Access has traditionally been the Office suite database program par excellence. It still remains that way, but with Office 2000 the face of Access is changing. This book will look at the traditional role of Access and its future uses in the Office suite.

Using VBA (Visual Basic for Applications), the user can program his or her own programs in what is essentially a subset of the Visual Basic programming languages. This is tremendously powerful, as it allows you to create great User Interfaces (forms etc), as a front end to actual database storage and manipulation. This continues to be one of the great strengths of programming Access VBA.

This book updates, expands and improves Beginning Access 97 VBA Programming, in an Office 2000 setting. All the great tutorial content, teaching people how to program with VBA in Access is there, but now majorly rewritten to take account of Office 2000.

  • Updated to take account of the Office 2000 facilities
  • Constructs a substantial example application with VBA
  • Database theory taught in the Wrox Beginning style

What does this book cover?

In this book, you will learn how to

  • Construct a substantial example application with VBA
  • Master the foundations of Visual Basic for Applications
  • Understand the concepts behind classes and objects
  • Understand how Automation can be used to link Office applications
  • Create custom objects using the Class Module feature
  • Debug your programs and implement robust error handling
  • Add support for multiple users
  • Publish your Access database on the Internet
  • Optimize and add polish to your finished database application

Who is this book for?

This book is for users who already have a basic knowledge of databases and the basic Access objects, such as tables, queries, forms and reports. You now want to expand on your existing knowledge of Access and wish to learn how to program in VBA. You don't need any prior programming experience, although a basic knowledge of Access macros would be helpful.

Introduction.

Chapter 1. Access 2000 – A Long Journey.

Chapter 2. Designing Applications.

Chapter 3. Introduction to Event Driven Programming.

Chapter 4. Creating Code.

Chapter 5. Controlling the Program.

Chapter 6. Using Access Objects.

Chapter 7. Using DAO.

Chapter 8. Data Management Techniques.

Chapter 9. External Data.

Chapter 10. Reports.

Chapter 11. Advanced Programming Techniques.

Chapter 12. Error Handling and Debugging.

Chapter 13. Using Classes.

Chapter 14. Libraries and Add-Ins.

Chapter 15. Automation.

Chapter 16. Multi-User.

Chapter 17. The Internet.

Chapter 18. Optimizing Your Application.

Exercise Solutions.

Appendix A. Choosing Between MSDE and Jet.

Appendix B. Choosing Between DAO and ADO.

Appendix C. ADO 2.1 Object Model.

Appendix D. Access Object Model.

Appendix E. Microsoft DAO 3.6 Object Library Reference.

Appendix F. Access Events.

Appendix G. ANSI Character Set.

Appendix H. ODBC and PWS.

 

Excercise Solutions
Download
Order.dot file is in this zip file (we left it off the CD - sorry!)
Download
ChapterPageDetailsDatePrint Run
WileyError in loading dll for main project

In the database icecream.mdb in the root directory of the installation for
the book's files, most readers will see the message Error in loading dll .
It happens when trying to go into the VBE, when trying to close Access 2000,
and at some other times. If the References dialog is opened from the Tools menu in the VBE, the following entry will be seen: MISSING: Microsoft
ActiveX Data Objects 2.1 Library . This will occur even though the path to
msado15.dll will be correct. This is due to a glitch in the references for
this particular project. To correct this, in the References dialog,
deselect the Missing entry and click OK to apply the deletion. Then, open
the References dialog again, and scroll down to Microsoft ActiveX Data
Objects 2.1 Library. Select it, click OK to apply the selection, then save
the database. You shouldn't see the error any longer.

Note that this doesn't occur on any of the other databases for the book.

Submitted by: David Liske
Tech Reviewer, Beginning Access 2000 VBA

19-Nov-991

79Page 79 Typing error

The second exercise should include the phrase 'event handlers' rather than 'even handlers'. The whole paragraph should read:

Take some time to read through the list of events and their uses. You will find that some events are more useful than others - in other words, you will find yourself writing custom event handlers for some events more often than for other events. Look at the list and try to think about which events you would most commonly handle with custom event handlers.

Thanks to Heather Wainwright

22-Feb-011

90Page 90 IsMissing function

The code at the bottom of the page has two unnecessary Else statements. It should simply read as follows:

Function MakeIceCream(Optional CocoaToBeAdded As Variant, _
Optional VanillaToBeAdded As Variant) As String

If IsMissing(CocoaToBeAdded) Then
CocoaToBeAdded = True
End If

If IsMissing(VanillaToBeAdded) Then
VanillaToBeAdded = True
End If



Thanks to Chris Kennedy

26-Jul-011

102Page 102 Table at bottom of page

In the table at the foot of this page the third value given in the left-hand column should read '22.345' rather than '12.345 + 10 ' as stated.

Thanks to Terry Franklin

24-Jul-011

106Page 106 Code Error

The code in bullet 2 should read:

Sub DateTest()
Dim datDec As Date
Dim datMay As Date

datMay = #5/1/1998#
datDec = #12/1/1998#

Debug.Print DatePart( m , datDec)
Debug.Print DateDiff( m , datMay, datDec)

Debug.Print August is & DateAdd( m , 3, datMay)
End Sub



Thanks to Michael Payne

22-Feb-011

116Page 116 Error in Code

n step 3 the line

Option Explicit

should be included in the General Declarations section.
Also the subroutine TestLocal should be declared as Public rather than Private. The code should then look like this:

Public Sub TestLocal()
Procedure1
Procedure2
Procedure1



Thanks to Charles E. Brown

22-Feb-011

116Step 1 Code Highlight

Step 1 should have the following lines highlighted:


    Dim intVariable1 As Integer
    Dim intVariable2 As Integer

    intVariable1 = 1
    intVariable2 = 2

    Debug.Print intVariable1
    Debug.Print intVariable 2

07-Oct-021

187Code Error
19-Jul-02We have just found an error in the code supplied in the Solutions.mdb database pertaining to the exercise in Chapter 6, pg 187. Thanks to Roger Pellatt
The original code snippet:

        For Each ctlControl In objAO.Controls
                ctlControl.FontName = strFont
        Next

should read:

         For Each ctlControl In Forms(objAO.Name).Controls
                ctlControl.FontName = strFont
         Next
19-Jul-021

198Page 198 typo

The last line of code at the bottom of the page should read as:

?CurrentDB().Name


Thanks to W.Xie

18-Jul-011

205Page 205 Table-type Recordset Objects

The following statement is incorrect:

This is the default type for any Recordset objects where the records come
from a single local or attached Access tables.

It should read as:

This is the default type for any Recordset objects where the records come from a single local Access table.


Many thanks to Mike MacSween

20-Mar-011

228Page 228 Error in Code

Code should read as:

Sub FindByPrice(curPrice As Currency)

Dim db As Database
Dim rec As Recordset
Dim strSQL As String
Dim strMatches As String
Dim intCounter As Integer

strSQL = tblSales

Set db = CurrentDb()
Set rec = db.OpenRecordset(strSQL, dbOpenSnapshot)

rec.FindFirst AmountPaid = & curPrice
Do While rec.NoMatch = False
intCounter = intCounter + 1
strMatches = strMatches & Chr$(10) & rec( SalesID )
rec.FindNext AmountPaid = & curPrice
Loop

Select Case intCounter
Case 0
MsgBox No orders cost & FormatCurrency(curPrice)
Case 1
MsgBox The following order cost & _
FormatCurrency(curPrice) & : & _
Chr$(10) & strMatches
Case Else
MsgBox The following & intCounter & orders cost & _
FormatCurrency(curPrice) & : & _
Chr$(10) & strMatches
End Select

rec.Close

End Sub





Thanks to Richard Giambrone

22-Feb-011

271Page 271 code error

In bullet point 4 at the bottom of the page the Function declaration should read as:

Function BuildResultsTable(strSQL As String, _
strTableName As String, _
lngRecordsAffected As Long) As Boolean


Thanks to W.Xie

18-Jul-011

307Page 307 Error in text
22-Feb-011

336Page 336 Code Error

n section 13 at the bottom of the page the code should read as follows:

txtValue =

With m_rptSales
.Filter =
.FilterOn = False
.txtFilter.Visible = False
.lblFilter.Visible = False
End With



Thanks to Michael Payne

22-Feb-011

374Page 374 Missing code

The code in point 3 at the top of the page should read as follows:

Dim prpCriteria As Property
Dim intWHEREPos As Integer
Dim tdf As TableDef

In addition, the first four lines of highlighted code in point 4 should read as:

'Now add a custom property to the table to hold the criteria
db.TableDefs.Refresh
Set tdf = db.TableDefs(sTableName)
Set prpCriteria = tdf.CreateProperty( Criteria )

18-Jul-011

444Typo

On the botton of page 444 says


       
Set clsRect = Nothing

it should be

Set objRect = Nothing
17-Jun-021

471Page 471 The MeanDelay property

n point 5 the first line should read:

Public Property Get MeanDelay() As Double

and not
Public Property Get MeanDelay() As Integer



Thanks to Gordon Wilmot

23-Feb-011

540Order.dot missing from CD

It appears the Order.dot template you need to run the Creating a Word Document Try It Out in Chapter 15 was omitted from the CD. We have added it to the code download section for the book on this site. Apologies if this caused any inconvenience.

Peter Morgan

03-Aug-991

541Incorrect code

At the bottom of page 540, two variables are declared as follows:
Private Const m_strDIR As String = ???C:\BegVBA\???
Private Const m_strTEMPLATE As String = ??? Order.dot???
However, the CreateOrderLetter code at the top of page 541 shows a variable that is not declared, g_strTEMPLATE:
Set m_objWord = New Word.Application
Set m_objDoc = m_objWord.Documents.Add(m_strDIR & g_strTEMPLATE)
The variable g_strTEMPLATE at the top of page 541 needs to be changed to m_strTEMPLATE, as in:
Set m_objWord = New Word.Application
Set m_objDoc = m_objWord.Documents.Add(m_strDIR & m_strTEMPLATE)
This is also how this variable is used in the code in IceCream15.mdb, which works correctly.
Submitted by: Pat Eisner
ZDU/SmartPlanet Student

***Note that the same errata occured on page 544 (bottom line) and page 545 (half-way down the page).

22-Nov-991

552Page 552 Code error

THe SELECT statement in the code snippet on this page should read as:

Else
strSQL = SELECT * FROM qryxSalesSummary WHERE CompanyName= & _
cboCompany.Column(1) &

20-Mar-011

557Page 557 Code snippet

The SELECT statement towards the bottom of the page should read as follows:


Else
strSQL = SELECT * FROM qryxSalesSummary WHERE CompanyName= & _
cboCompany.Column(1) &

12-Apr-011

594Page 594 Coding error

The portion of code that verifies the new password does not exit the
function if the check fails, but carries on and changes the password
anyway. The code segment at the the top of page 594 should read:

If strNew <> strVerify Then
MsgBox Your new password and the verification of your & _
new password do not match. & _
vbCrLf & vbCrLf & _
Please try again. , vbExclamation
GoTo ChangePassword_Exit


Thanks to Gordon Clark

24-Jul-011

687Error in code

Dave Sussman comments....

Many, many apologies for this confusion - blame it entirely on me.

I'm not entirely sure how this came about (or how it's not been noticed before), but there's an error in the code.

The inner loop should be:

        For Each ctlControl In Forms(objAO.Name).Controls
            ctlControl.FontName = strFont
        Next

Notice that the collection we are looping through is not objAO.Controls, but the Controls collection of the open form.

It is OK to use the open form because it is open in design view, and therefore when we save we can save the changes.

17-Jun-021

700Page 700 Error in code

The code should read as follows:

Public Property Let Height(dblParam As Double)
dblHeight = dblParam
Sides(1).Length = dblParam
Sides(3).Length = dblParam

End Property

Public Property Let Width(dblParam As Double)
dblHeight = dblParam
Sides(2).Length = dblParam
Sides(4).Length = dblParam

End Property



Thanks to David Sussman

22-Feb-011

709Page 709 Error in code

The code on p709 should read as follows:

Dim clsUser As New cUser

'set the user name - this reads in the current user
'password and last change date
clsUser.Name = CurrentUser()

'see if the password needs changing
If clsUser.PasswordNeedsChanging Then
'password has expired so force a password change
DoCmd.OpenForm frmPasword , . . .
End If

'change the password
If clsUser.PasswordChange ( OldPassword , NewPassword , strResult) = True Then
MsgBox Password change succeeded.
Else
MsgBox strResult
End If




Thanks to David Sussman

18-May-011