Results 1 to 11 of 11
  1. #1
    kattatonic1 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Location
    Toronto, Canada
    Posts
    77

    Lightbulb Open a form with a different query applied

    Have frmPositions working great. Its Record Source is qryPositions, working great.



    I have created a parameter query, qryPositionsFindPos, that prompts for a Positon#, and produces the right record. I would like to apply this query to frmPositions now. Scratching head. I copied the form and made the duplicate's record source qryPositionsFindPos and it works great. Having duplicate forms is not a great idea. I would rather apply the second query whenever I want to the one form.

    Tried Macro to open query from button and it opens the query itself, doesn't apply the query to the form.

    Tried Docmd.OpenQuery and it returns an error message.

    I have not coded for eons. Using very little code, some macros. Simple database.

    Any help appreciated, particularly because once I have it working in the Positions world of my db, I'd like to apply the technique to more than one form/record source actually.

    Kay from Toronto

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    In your form's load event you could have some code that would run or not, depending on an Open Args value

    You can adjust your form's recordset with VBA. This example uses open args and to determine the form's recordsource. You can pass open args in a Docmd.OpenForm statement.


    untested...
    if Me.OpenArgs <> "" then
    Me.RecordSource= "SELECT * FROM qryPositions WHERE [SomeField] = " Me.OpenArgs
    else
    Me.RecordSource= "SELECT * FROM qryPositions"
    end IF

    The WHERE clause in the SQL can replace your parameterized query.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Another option:

    DoCmd.OpenForm "formname", , , "[SomeField]=" & Me.somecontrolname

    Also eliminates the dynamic parameter (I never use them) in query.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by June7 View Post
    ...

    DoCmd.OpenForm "formname", , , "[SomeField]=" & Me.somecontrolname

    .
    June,

    Have you noticed that using Docmd and the Where Criteria applies the criteria to the form's "filter"? I have used this Docmd with the Where criteria for ever and then noticed while working in 2010 that the form's filter was applied. The Where criteria did not get applied to the form's RecordSource. Just wondering if my previous data bases are getting the filter applied when I thought it was not.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Yes, it sets the form filter property. Just don't let the form get saved with the setting.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by June7 View Post
    Just don't let the form get saved with the setting.
    I was just thinking about that...

  7. #7
    ipisors is offline Access Developer
    Windows XP Access 2007
    Join Date
    Sep 2013
    Posts
    119
    Quote Originally Posted by ItsMe View Post
    I was just thinking about that...
    Just another 2 cents, I never use the form's filter property and not really ever the Where either....Just dynamically set the recordsource either by using a vba/sql statement or by using a querydef whose .sql property gets manipulated. I agree, messing with the filter gets thorny.

    Plus I'm using listboxes and comboboxes to dynamically restrict the form's recordsource (i.e., Select * from tbl_something where ID=" & me.Listbox, etc) anyway, that filters would soon be lost and irrelevant, or worse yet, saved into design like you mentioned.

    It's kind of the 'balance' in between the two theories of those who have grown to loathe bound forms, vs. those who use nothing but bound forms, in between because I like bound forms but as long as I'm continually able to change the 'binding'.

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by ipisors View Post
    Plus I'm using listboxes and comboboxes to dynamically restrict the form's recordsource (i.e., Select * from tbl_something where ID=" & me.Listbox, etc) anyway, that filters would soon be lost and irrelevant, or worse yet, saved into design like you mentioned.
    This is typically my approach too. The only thing is, I have been unwittingly setting the filter property. For what ever reason, it did not become apparent to me until after I starting using 2010. Now I need to go back over production DB's and reinforce constraints. I am of the mindset that the filter tool is for public interface. Now I just need to make sure I am practicing what I preach.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    I've never had issue with using the WHERE CONDITION argument for forms and reports. I have only 1 case where I change the RecordSource property of a report.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi all -

    Yes, the "where" on opening a form will set the "Filter" property, and if you go in to form design view you will see it.

    But, unless you have VBA code or a macro that also sets the FilterOn property to True (this property is not in the property sheet), or runs DoCmd.Applyfilter, the filter will not be applied when the form is opened.

    You can also turn the filter on or off while the form is open.

    John

  11. #11
    kattatonic1 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Location
    Toronto, Canada
    Posts
    77
    Just so you know what I ended up using. I created a macro with just the OpenForm command. In the Filter condition I put the name of the parameter query. It works beautifully. I know some of you seasoned developers are not huge fans of macros but this one needs no other info or commands in the macro, and I can apply it in many places.

    For those who suggest other things: all techniques appreciated! I am learning so much. I end up applying the ideas somewhere sometime. Where I have to, I am stumbling through the code to make it work and getting better at it, making notes, etc.

    Many thanks!

    Kay
    Toronto
    Access 2010

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 10-02-2013, 11:14 AM
  2. Replies: 2
    Last Post: 08-07-2013, 07:44 AM
  3. Help on report to open form to open query...
    By saseymour in forum Programming
    Replies: 13
    Last Post: 07-16-2013, 08:11 AM
  4. ODBC Call Fail - Only when totals applied
    By wvuatrrd in forum Queries
    Replies: 3
    Last Post: 11-04-2010, 12:52 PM
  5. How to open a form with filter applied?
    By rkm360 in forum Access
    Replies: 1
    Last Post: 03-18-2009, 09:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums