Thanks for the quick reply.
This is what I have now. There's no more error, however when I run the
code,
it asks me to enter in the Type criteria, even though I selected one on
the
form.
Any ideas?
qdf.SQL = "SELECT * FROM MyTable N " & _
"WHERE N.INIT_DT >= '" & Me.txtStartDate.Value & _
"' AND N.INIT_DT <= '" & Me.txtEndDate.Value & _
"' AND N.TYPE = '" & Me.typebox.Value & "';"
:
Also, as you are using date, I'm not sure if you must enclose them
with
single quote ' or with sharp #.
--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail:
http://cerbermail.com/?QugbLEWINF
"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam
please)>
wrote in message Even if the Type is another field, you must use another AND and not
a
second WHERE. You can have only one WHERE clause for each Select
statement (but you can have multiple Where clauses in your query if
you
have multiple Select statements, for example in an UNION query).
--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail:
http://cerbermail.com/?QugbLEWINF
I've got this to work for the form that I have, however I need some
assistance on some additional features. I'd like to add additional
criteria,
however my syntax is not correct. I've tried multiple versions,
with
the
following seeming like the most sense:
qdf.SQL = "SELECT * FROM MyTable N " & _
"WHERE N.INIT_DT >= '" & Me.txtStartDate.Value & _
"' AND N.INIT_DT <= '" & Me.txtEndDate.Value & _
"WHERE N.TYPE = '" & Me.typebox.Value & "';"
Where type is another field in table N, and typebox is another
combo
box
on
the form. What's wrong with this.
Also, if possible, how can I add the ability to not select a field
from
combo box "type box", yet still display records.
I know how to do this in the design mode: Like "*" & [forms]!
.........
Thanks
:
Hi Van:
You are correct--I blew it big time by focusing on the original
criteria
that was shown. Me.bad. Thank You for adding the correction.
Frankie:
Here is an example of modifying the SQL string using VBA code
behind
a
form.
In this example, I have decided to remove the call to the DateAdd
function
that I originally included. The only caveat is that you will not
pick
up
records that match the ending date entered if a time other than a
default of
midnight (0) is included with the saved record.
This example uses a search form with two text boxes, which are
named
txtStartDate and txtEndDate. It also assumes that you have another
form,
bound to a pass through query, which is used to display the
results,
ie.
"frmDisplayPassThroughQueryResultsForm" is bound to
"qptNameOfYourPassThroughQuery".
A pass through query produces a read only recordset, so you will
not
be
able
to edit the records shown. A command button named cmdRunQuery on
the
search
form includes the following code for it's click event procedure:
Private Sub cmdRunQuery_Click()
On Error GoTo ProcError
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Set db = CurrentDb()
Set qdf = db.QueryDefs("qptNameOfYourPassThroughQuery")
qdf.SQL = "SELECT * FROM MyTable N " & _
"WHERE N.INIT_DT >= '" & Me.txtStartDate.Value & _
"' AND N.INIT_DT <= '" & Me.txtEndDate.Value & "';"
' Note: As an alternative, modify the SELECT * FROM part to select
just
' the fields you actually need instead of, if you can get by
displaying
less
fields.
DoCmd.OpenForm "frmDisplayPassThroughQueryResultsForm"
ExitProc: 'Clean up
On Error Resume Next
qdf.Close
Set qdf = Nothing
db.Close
Set db = Nothing
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure cmdRunQuery_Click..."
Resume ExitProc
End Sub
Hope this helps.
Tom
_______________________________________
:
Since Pass-Through Queries are proccessed by the server end,
Access
simply
passes the entire SQL String to the server end without
pre-processing
AFAIK.
This means that the Expression Service won't get involved to
resolve
references and you cannot use the reference to the Form Controls
as
Parameters.
You need to modify the SQL String (by VBA code) to include the
StartDate
and
EndDate explicitly before running the Pass-Through Query.