Library code snippets
Parameters in a DAO parameter query
As you probably know, in Access a parameter query displays one or
more predefined dialog boxes that prompt you for a parameter value.
In most cases, you use a parameter query to determine criterion. For
example, if you limited a query's result by the parameter, <[Please
Enter A Date], then when you ran the query Access would display a
prompt and ask you to Please Enter A Date and filter the records
accordingly.
When you manipulate these queries in DAO through VBA, however, you'll
need to supply the parameter value before you open the recordset
object. If you don't, DAO generates an error.
To do so, access the Parameters collection of the DAO querydef
object. A querydef is a query's definition, or blueprint. It tells DAO
what the query's layout should be, while a recordset contains the
results generated by the querydef. To illustrate, take a look at the
following code:Private Sub cmbRunParam_Click()
Dim wrk As DAO.Workspace
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim qdf As QueryDef
Set wrk = CreateWorkspace("", "Admin", "", dbUseJet)
'Change database path
Set db = wrk.OpenDatabase("D:Examplesdb1.mdb")
Set qdf = db.QueryDefs("qryParamQuery")
qdf.Parameters("[Please Enter a Date]") = #8/15/2000#
Set rst = qdf.OpenRecordset()
rst.MoveLast
MsgBox "There are " & rst.RecordCount & " projects to"
_
& vbCr & "complete before this date."
Set rst = Nothing
Set qdf = Nothing
Set db = Nothing
Set wrk = Nothing
End Sub
Related articles
Related discussion
-
Automating Excel from VB6.0
by epurdy (0 replies)
-
VB6 system conversion using VBA to Word 2007
by b.macgregor@vodamail.co.za (0 replies)
-
video not working with visual basic
by Jupiter 2 (9 replies)
-
Hyperterminal Data
by sengreen (1 replies)
-
vb6 - custom font
by Ruffsta3 (0 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
This thread is for discussions of Parameters in a DAO parameter query.