Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 11th, 2007, 12:34 PM
Authorized User
 
Join Date: Sep 2006
Posts: 73
Thanks: 6
Thanked 0 Times in 0 Posts
Default Help Creating Snapshot Query

Hello All:

I have a subroutine that I pieced together off of the net and I got it working for what I want to do. Basically I am doing a search from combo boxes and opening up a query window. The query is editable and I don't want it to be. Can someone lend me a hand on how to open up the query window in Snapshot mode? My code for subroutine is below.

Thanks..Tony
================================================== ===

Private Sub scmdSearch_Click()
    Dim db As Database
    Dim QD As QueryDef
    Dim where As Variant

    Set db = CurrentDb()

    On Error Resume Next
    db.querydefs.Delete ("Dynamic_Query")
    On Error GoTo 0

    where = Null
    where = where & " AND [RecordNumber] = + Me![scboRecordNumber] + "
    where = where & " AND [EnteredBy] = '" + [scboEnteredBy] + "'"
    'where = where & " AND [EnteredDate] = + Me![scboEnteredDate] + "
    where = where & " AND [RequestingFacility] = '" +
            Me![scboRequestingFacility] + "'"
    where = where & " AND [RequestedBy] = '" + Me![scboRequestedBy] +
            "'"
    where = where & " AND [CurrentContact] = '" +
            Me![scboCurrentContact] + "'"
    where = where & " AND [OrdersetName] = '" + Me![scboOrdersetName]
            + "'"
    where = where & " AND [OrderItemName] = '" +
            Me![scboOrderItemName] + "'"
    where = where & " AND [OrderSection] = '" + Me![scboOrderSection]
            + "'"
    where = where & " AND [OrdersetFormat] = '" +
            Me![scboOrdersetFormat] + "'"
    where = where & " AND [OrdersetType] = '" + Me![scboOrdersetType]
            + "'"
    'where = where & " AND [RequestedDate] = + Me![scboRequestedDate]
            + "
    where = where & " AND [ChangeApproved] = '" +
            Me![scboChangeApproved] + "'"
    'where = where & " AND [ChangeApprovalDate] = +
            Me![scboChangeApprovalDate] + "
    where = where & " AND [AssignedAnalyst] = '" +
            Me![scboAssignedAnalyst] + "'"
    'where = where & " AND [CompletedDate] = + Me![scboCompletedDate]
            "

    'MsgBox "Select * from BHCS_Change_Request " & (" where " +
            Mid(where, 6) & ";")
    Set QD = db.CreateQueryDef("Dynamic_Query", _
            "Select * from BHCS_Change_Request " & (" where " +
            Mid(where, 6) & ";"))
    DoCmd.OpenQuery "Dynamic_Query"

End Sub
================================================== ===============

 
Old July 12th, 2007, 06:34 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Create a report from the query, and open the report instead.

Did that help?


mmcdonal
 
Old July 12th, 2007, 06:42 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Also, there is an easier way to do this using criteria in the query itself, rather than passing this string. For example, on the column in the query for RecordNumber, add this criteria:

[Forms]![frmYourFormName].[scboRecordNumber]

The query will go out and fetch this itself when you open the report that uses the query as the data source. So your only code is to open the report.

mmcdonal
 
Old July 12th, 2007, 01:33 PM
Authorized User
 
Join Date: Sep 2006
Posts: 73
Thanks: 6
Thanked 0 Times in 0 Posts
Default

Thank you mmcdonal:

That sure was easier.


Tony






Similar Threads
Thread Thread Starter Forum Replies Last Post
Snapshot doesn't work roy_mm Reporting Services 0 July 22nd, 2008 08:44 AM
Chapter 5 Exercises Creating a non-Parameter Query mm58 BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 0 March 1st, 2008 08:18 PM
How to Query Snapshot of Data in % feets SQL Server 2000 4 November 8th, 2007 04:41 AM
Creating Cross-Tab query in SQL? WebLadyBug SQL Server ASP 0 March 9th, 2007 09:57 AM
Creating Reports from a Query by Form jBranch Access VBA 0 March 3rd, 2004 09:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.