By Ken Getz, Paul Litwin, Andy Baron
Book Price: $49.95 USD
£35.50 GBP
PDF Price: $31.99
Cover | Table of Contents | Colophon
query by
example (QBE) grid, plus the three SQL-specific
queries—give you a tremendous amount of power and flexibility
in selecting, sorting, summarizing, modifying, and formatting the
data stored in your tables before presenting it to the user on forms
or printing it on reports. Access queries can be intimidating at
first, but mastering queries will give you complete control over the
appearance and functionality of your forms and reports. And Access
queries are flexible—once you learn how to control them, you
can use them in places where you might have written less efficient
program code.[Type of Music?]
Type of Music?
Text
|
Query field
|
Data type
|
Control type
|
Parameter reference
|
|---|
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.01-10.MDB, open the tblGrades and tblLookup
tables, both shown in Figure 1-27. The first table,
tblGrades, includes a row for each student and the
student's numeric grade. The lookup table,
tblLookup, contains two columns for the ranges of numeric grades and
a third for the corresponding letter grade.
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 any invalid 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:<N/A>), will show.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.01-14.MDB
into your database.|
FieldName
|
DataType
|
FieldSize
|
Index
|
|---|---|---|---|
|
ClientID
|
AutoNumber
|
Long Integer/Increment
|
Yes, primary key
|
|
FirstName
|
Text
|
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 = -12632256 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