Cover | Table of Contents | Colophon
[Type of Music?]
Type of Music?
Text
|
Query field
|
Data type
|
Control type
|
|---|
Public Function acbGetRandom(varFld As Variant) ' Though varFld isn't used, it's the only way to force the query ' to call this function for each and every row. Randomize acbGetRandom = Rnd End Function
acbGetRandom([State])
Between operator. For example, you have a table of
students and their grades, and a table of grade ranges and the
matching letter grade. Though there are lots of ways to solve this
problem with complex expressions and VBA, you know there must be a
solution involving just queries. You need a way to join these two
tables, finding matches when a value in the first table is between
two values in the second table.
=. To perform these types of joins, you must
specify the join in the criteria of the linking field.
SELECT Company, Address1, Address2, Address3, City, StateProvince, ZipPostalCode, Country FROM tblClients WHERE Country = "U.S.A."
<N/A>, which can be used to enter a null
value for the field. You don't want your users to be able to
enter all sorts of "garbage" entries, just
<N/A> (or some other special code).
<N/A> row to the row source for the combo
box. We suggest using <N/A> rather than
simply N/A to force the entry to sort to the top
of the combo box list. To make this work right, you'll need to
make the combo box unbound and use a bit of VBA code to move values
between the underlying table and the combo box.
<N/A> entry on
a form of your own, follow these steps:
|
Property
|
Value
|
|---|---|
|
Name
|
cboArtistID
|
|
ControlSource
|
Option
Compare
Binary statement in the declarations section of a
module to force VBA to make string comparisons that are
case-sensitive within the bounds of that module, but this affects
only string comparisons made in a VBA module, not comparisons made by
the Jet engine. Thus, even when you run the query from a VBA
Option
Compare
Binary procedure, any comparisons made in the
query are case-insensitive. The problem is that the Jet engine
doesn't know how to make case-sensitive string comparisons
using any of the standard query operators. Fortunately, you can
create your own case-sensitive string-comparison function in an
Option
Compare
Binary module and call this function from the
query. This solution shows you how to create the VBA function and how
to use it to perform case-sensitive searches.
|
FieldName
|
DataType
|
FieldSize
|
Index
|
|---|---|---|---|
|
ClientID
|
AutoNumber
|
Long Integer/Increment
|
Yes, primary key
|
Public Sub CreatePrmRst1( )
' Example of creating a recordset based on a parameter query.
' This example fails!
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb( )
' Open the form to collect the parameters.
DoCmd.OpenForm "frmAlbumsPrm", , , , , acDialog
' OK was pressed, so create the recordset.
If IsFormOpen("frmAlbumsPrm") Then
' Attempt to create the recordset.
Set rst = db.OpenRecordset("qryAlbumsPrm")
rst.MoveLast
MsgBox "Recordset created with " & rst.RecordCount & _
" records.", vbOKOnly + vbInformation, "CreatePrmRst"
rst.Close
Else
' Cancel was pressed.
MsgBox "Query canceled!", vbOKOnly + vbCritical, _
"CreatePrmRst"
End If
DoCmd.Close acForm, "frmAlbumsPrm"
Set rst = Nothing
Set db = Nothing
End Sub
Option Compare Database Option Explicit Private Const conWhite = 16777215 Private Const conGray = -2147483633 Private Const conIndent = 2 Private Const conFlat = 0
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyPageUp, vbKeyPageDown
KeyCode = 0
Case Else
' Do nothing.
End Select
End Sub
|
Property
|
Value
|
|---|---|
|
RecordSource
|
Private Sub Form_Load ( ) acbRestoreSize Me End Sub
Private Sub Form_Unload (Cancel As Integer) acbSaveSize Me End Sub
New keyword and user-defined collections.
Private Sub cmdViewAnother_Click( ) Call acbAddForm End Sub
Private Sub cmdCloseAll_Click( ) Call acbRemoveAllForms End Sub
Private Sub Form_Close( ) Call acbRemoveForm(Me) End Sub
=1
|
Parameter
|
Sample value
|
|---|---|
|
Type of music?
|
Rock
|
|
Starting year?
|
1960
|
|
Setting
|
Purpose
|
Sample
|
|---|
If...Then statement with the following basic
structure:
If (some condition) Then Me.Section(acPageHeader).Visible = True Else Me.Section(acPageHeader).Visible = False End If
http://msdn.microsoft.com to find
the download.
Private Sub PageHeader0_Format(Cancel As Integer, FormatCount As Integer)
[txtPageTotal] = 0
End Sub
Private Sub ReportHeader0_Format(Cancel As Integer, FormatCount As Integer)
[txtPageTotal] = 0
End Sub
Private Sub Detail1_Print(Cancel As Integer, PrintCount As Integer)
[txtPageTotal] = [txtPageTotal] + [Freight]
End Sub
Private Sub Report_NoData(Cancel As Integer)
MsgBox "Sorry, no records match these criteria!", _
vbExclamation, "No Records to Print"
Cancel = True
End Sub
Mod operator to
determine whether the page is odd or even and makes the appropriate
controls visible or invisible.
Private Sub PageHeader_Format(Cancel As Integer, FormatCount As Integer)
On Error GoTo PageHeader_FormatError
Dim fIsEven As Boolean
fIsEven = acbIsEven(Me.Page)
Me![lblTitleLeft].Visible = Not fIsEven
Me![lblTitleRight].Visible = fIsEven
End Sub
Private Sub GroupFooter0_Print(Cancel As Integer, PrintCount As Integer)
Dim sngLineTop As Single
Dim sngLineLeft As Single
Dim sngLineWidth As Single
Dim sngLineHeight As Single
Const acbcSMTwips = 1
Const acbcDSSolid = 0
Me.ScaleMode = acbcSMTwips
Me.DrawStyle = acbcDSSolid
' Set the coordinates for the line.
sngLineTop = Me![lblConditions].Top
sngLineLeft = 0
sngLineWidth = 100
With Me![txtConditions]
sngLineHeight = .Top + .Height
End With
' Draw the line.
Me.Line (sngLineLeft, sngLineTop)-Step(sngLineWidth, sngLineHeight), , BF
End Sub
' Shade this row or not? Dim fShade As Boolean
lngLanguage = acbAccessLanguage( )
Private Sub Form_Load( )
Dim prt As Printer
lstPrinters.RowSourceType = "Value List"
For Each prt In Application.Printers
lstPrinters.AddItem prt.DeviceName & " on " & prt.Port
Next prt
End Sub
Private Sub FillPrinterList(ctl As Control)
' Fill the provided control (ctl) with a list of printers. This
' will cause a runtime error if ctl isn't a list or combo box.
Dim prt As Printer
ctl.RowSourceType = "Value List"
For Each prt In Application.Printers
ctl.AddItem prt.DeviceName
Next prt
End Sub
DoCmd.OpenReport strReport, View:=acViewPreview
With Reports(strReport).Printer
Me.txtCopies = .Copies
Me.grpOrientation = .Orientation
Me.grpPaperSize = .PaperSize
End With
strReport = Me.cboReportList
With Reports(strReport).Printer
.Copies = Me.txtCopies
.Orientation = Me.grpOrientation
.PaperSize = Me.grpPaperSize
End With
Private Sub cboReportList_AfterUpdate( )
Dim strReport As String
Dim rpt As Report
On Error GoTo HandleErrors
strReport = Me.cboReportList
DoCmd.OpenReport strReport, View:=acViewPreview, WindowMode:=acHidden
With Reports(strReport)
With .Printer
Me.txtDevice = .DeviceName
Me.txtDriver = .DriverName
Me.txtPort = .Port
End With
Me.chkDefault = .UseDefaultPrinter
End With
ExitHere:
DoCmd.Close acReport, strReport
Exit Sub
HandleErrors:
MsgBox "Error: " & Error & " (" & Err & ")"
Resume ExitHere
End Sub
|
Field name
|
Field type
|
Default value
|
|---|---|---|
|
DateCreated
|
Date/Time
|
=Now( )
|
|
UserCreated
|
Text (20)
| |
|
DateModified
|
Date/Time
|
If...Then statement that will branch based on the
value of the form's NewRecord property. The code of the event
procedure should look like this:
Private Sub Form_Current( )
If Me.NewRecord Then
' Do something for a new record.
Else
' Do something for an existing record.
End If
End Sub
Private Sub Form_Current( )
' Determine if this is a new record and change the bitmap
' of the imgFlag control to give the user visual feedback.
' See Solution 9.7 for an explanation of using the
' PictureData property.
If Me.NewRecord Then
Me!imgFlag.PictureData = Me!imgFlagNew.PictureData
Else
Me!imgFlag.PictureData = Me!imgFlagEdit.PictureData
End If
End SubLike operator with the first letter of the
person's last name, but that produces too many names. Is there
any way to search for records that sound alike?
Soundex: acbSoundex([LastName])
Null.
|
Parameter
|
Description
|
Example
|
|---|---|---|
Set wrk = DBEngine.Workspaces(0)
' Directly open the external database. It will be opened
' nonexclusively, read-write, and with type = Access.
Set dbExternal = _
wrk.OpenDatabase(acbGetLinkPath("tblCustomer"),, False, False, "")
' Create a table-type recordset based on the external table.
Set rstCustomer = dbExternal.OpenRecordset("tblCustomer", dbOpenTable)
Call acbListFields (strName, fTable, strOutputTable)
DoCmd.OpenForm "frmBackup"
DoEvents statement, which gives Windows time to
handle its own chores while your code is running. A group of four
solutions covers the details of creating list-filling functions,
passing arrays as parameters, sorting arrays, and filling a list box
with the results of a directory search. The final two solutions cover
some details of working with Data Access Objects (DAO): how to set
and retrieve object properties, whether the properties are built-in,
and how to tell whether an object exists in your application.
? A( )
? A( )
********************************
Procedure Profiling
3/13/2001 3:29:11 PM
********************************
+ Entering procedure: A( )
+ Entering procedure: B
+ Entering procedure: C
+ Entering procedure: D
- Exiting procedure : D 101 msecs.
+ Entering procedure: D
- Exiting procedure : D 100 msecs.
- Exiting procedure : C 301 msecs.
+ Entering procedure: C
+ Entering procedure: D
- Exiting procedure : D 100 msecs.
+ Entering procedure: D
- Exiting procedure : D 100 msecs.
- Exiting procedure : C 300 msecs.
- Exiting procedure : B 701 msecs.
+ Entering procedure: B
+ Entering procedure: C
+ Entering procedure: D
- Exiting procedure : D 100 msecs.
+ Entering procedure: D
- Exiting procedure : D 100 msecs.
- Exiting procedure : C 300 msecs.
+ Entering procedure: C
+ Entering procedure: D
- Exiting procedure : D 100 msecs.
+ Entering procedure: D
- Exiting procedure : D 101 msecs.
- Exiting procedure : C 301 msecs.
- Exiting procedure : B 701 msecs.
- Exiting procedure : A( ) 1513 msecs.DoEvents
statement, which effectively yields time to Windows so that Access
can perform whatever other tasks it must. Effective use of
DoEvents can make the difference between an Access
application that hogs Access's ability to multitask and one
that allows Access to run smoothly while your VBA code is executing.
For intI = 0 To 1500 Step 1 Me!lblGrow1.Width = Me!lblGrow1.Width + 5 ' Without this call to Repaint, you'll ' never see any changes on the screen. Me.Repaint Next intI
DoEvents, try these steps:TestUCase 5
TestSort 6
|
Control
|
Property
|
Setting |
|---|
|
Object name
|
Object type
|
|---|---|
Private Sub Form_Load( ) Dim lngDummy As Long lngDummy = cboFast.ListCount End Sub
Where clause:
WHERE (((tblOrderDetailsNoIndexes.[Quantity])=13)) OR (((tblOrderDetailsNoIndexes. [Menu#])=25))
/) operator to divide two numbers, but
this operator is optimized for floating-point division. If
you're dividing integers, you should use the backslash
(\) integer division operator instead. With
\, Access works at the integer level instead of
the floating-point level, so computation is faster. (Of course, this
is useful only if you're assigning the results of the division
operation to an integer. If you care about the fractional portion of
the division, you'll need to use floating-point math and the
/ operator after all.) For example, instead of:
intX = intY / intZ
FloatDivision( )
IntegerDivision( )
AutoKeys macro to create keyboard shortcuts for
your application, but you'd like the shortcut keys to change
based on the currently active form. Is there an easy way to create
context-sensitive keyboard shortcuts in Access?
AutoKeys macro to create keyboard shortcuts for
your application, but you'd like the shortcut keys to change
based on the currently active form. Is there an easy way to create
context-sensitive keyboard shortcuts in Access?
AutoKeys macros to your own application, follow
these steps:
mcrNoMenus macro sheet in
09-02.MDB has no macro actions.
Private Sub Form_Activate( ) DoCmd.ShowToolbar "Form View", acToolbarNo End Sub Private Sub Form_Deactivate( ) DoCmd.ShowToolbar "Form View", acToolbarWhereApprop End Sub
Private Sub tglMark_Click( )
' If the toggle button is depressed, mark this record;
' otherwise, return to the previously saved record.
If Me!tglMark Then
Call acbHandleMarkReturn(conMark)
Else
Call acbHandleMarkReturn(conReturn)
End If
End Sub
|
Property
|
Value
|
|---|---|
|
DefaultView
|
Single Form
|
|
ScrollBars
|
|
Field name
|
Data type
|
|---|---|
|
ActionDate
|
Date/Time
|
|
Action
|
Number (Byte)
|
|
UserName
|
|
Table name
|
Field name
|
Field type
|
Primary key?
|
|---|---|---|---|
|
tblGroups |