ok, forget about my first suggestion, here is what you can do. Try
using an SQL statement, i know this method will work because i
implemented it in a database i am working on.
Private Sub cmdPreviewCurrent_Click()
On Error GoTo Err_cmd_PreviewCurrent_Click
'variable declaration
Dim stDocName As String, queryname As String, MySql as string, cr
as string
Dim curr as string
Dim mydb As Database, tblFld As QueryDef
Set mydb = CurrentDb()
'deletes previous query under the name qry_temp
queryname = "qry_temp_report" 'base report off of this
query
DoCmd.DeleteObject acQuery, queryname
'sets tblFld equal to the queryname, will later be used to run
query
Set tblFld = mydb.CreateQueryDef(queryname)
'sets up the variable locations
'place holder
cr = Chr$(13)
curr = me.ID 'change 'ID' to your field that you want to
filter by
'SQL Statement
'change 'tblMyTable' to your table
MySql = "SELECT tblMyTable.* FROM tblMyTable WHERE
tblMyTable.[Equipment_ID] LIKE '" & curr & "*';" & cr
'runs the sql to make a custom report
tblFld.SQL = MySql
'opens up report
stDocName = "rptMyReport" 'rptMyReport is the name of your
report
DoCmd.OpenReport stDocName, acPreview
Exit_cmd_PreviewCurrent_Click:
Exit Sub
Err_cmd_PreviewCurrent_Click:
MsgBox Err.Description
Resume Exit_cmd_PreviewCurrent_Click
End Sub
Just make a command button and add that code. Then in the query
window, create a query and name it 'qry_temp_report' and save it. You
don't have to make any changes to the query, just create one with that
name, the SQL statement in the code will do what you need it to. then
base your report off of that query and change this code to match yoru
variables.
|