Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 11th, 2007, 12:34 PM
Authorized User
Points: 336, Level: 6
Points: 336, Level: 6 Points: 336, Level: 6 Points: 336, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2006
Location: , , .
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
================================================== ===============

Reply With Quote
  #2 (permalink)  
Old July 12th, 2007, 06:34 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
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
Reply With Quote
  #3 (permalink)  
Old July 12th, 2007, 06:42 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
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
Reply With Quote
  #4 (permalink)  
Old July 12th, 2007, 01:33 PM
Authorized User
Points: 336, Level: 6
Points: 336, Level: 6 Points: 336, Level: 6 Points: 336, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2006
Location: , , .
Posts: 73
Thanks: 6
Thanked 0 Times in 0 Posts
Default

Thank you mmcdonal:

That sure was easier.


Tony

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 08:57 AM.


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