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
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access 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 January 31st, 2005, 04:35 PM
Authorized User
 
Join Date: Dec 2004
Location: Las Vegas, NV, USA.
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to parse filter from a form to a main form

Hi there,
 I posted this thread few days ago, still couldn't solve it, if anyone can give me some suggestions, I will appreciate it!

 I use a dialog "menu" to collect search criteria.

 The "menu" dialog includes:
 client(combo box)
 Open_order(check box)
 submit(button)
 Private Sub submit_Click()
   DoCmd.OpenForm "order"
 End Sub
  (I am wondering how can I set criteria here and parse it to the "order" form)

 After the user click "submit" button in the "menu", a form named "order" should display all records which satisfy with the criteria.

 In the "order" form, I had a query

 My questions are as follows:
 If user doesn't select anything from the combo box(I should see all the clients in the "order" form).
  If the open_order isn't checked, I would see all the open orders in the "order" form.
  I don't know how can I set these criteria correctly in the query under the "order" form?



flyfish

flyfish
__________________
flyfish
Reply With Quote
  #2 (permalink)  
Old February 1st, 2005, 05:36 AM
Friend of Wrox
 
Join Date: Jan 2005
Location: , , United Kingdom.
Posts: 100
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Flyfish,

You could create an unbound form and supply its recordsource at run time with a routine like this -

Private Sub cmdSubmit_Click()
Dim strSQL As String
Dim frm As Form

    'Build the basic Recordset
    strSQL = "SELECT tbl_Orders.Order_ID, tbl_Orders.Order, " & _
        "tbl_Orders.Customer_ID, tbl_Orders.Order_Open " & _
        "FROM tbl_Orders"

    'If either criteria is supplied then add a where clause
    If cboCustomer <> 0 Or chkOpen Then
        strSQL = strSQL & " WHERE ("

        'Now build the where clause using the criteria selected
        If cboCustomer <> 0 Then strSQL = strSQL _
                & "((tbl_Orders.Customer_ID)=" & cboCustomer & ") AND"

        If chkOpen Then strSQL = strSQL & _
            "((tbl_Orders.Order_Open)=" & chkOpen & ") AND"

        'Now remove the last and
        strSQL = Left(strSQL, Len(strSQL) - 4)

        'And apply the closing bracket
        strSQL = strSQL & ");"

    Else
        'Just append the closing ;
        strSQL = strSQL & ";"
    End If

    'Open the Orders form and set its recordsource property to the SQL we created
    DoCmd.OpenForm "Frm_Order"
    Forms![frm_Order].Form.RecordSource = strSQL

End Sub

The controls on your order form should be bound to the fields in your basic recordset. The FORMS recordsource remains unbound though. Let us know if this works for you.

HTH

Jp
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
Sizing Main/Sub Form Brendan Bartley Access 2 September 11th, 2006 07:50 AM
C++ Builder 6 - Contolling the Main Form rowin C++ Programming 0 January 30th, 2006 08:30 AM
Populate Main/Sub Form Brendan Bartley Access 8 December 9th, 2005 06:30 AM
Passing Value from main form to Popup Form smartgir Access VBA 0 February 26th, 2004 06:26 PM
Filter subform from main form DBoulos Access VBA 2 October 30th, 2003 12:20 PM



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


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