Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2011
    Location
    USA
    Posts
    13

    Unanswered: Creating a Form Filter On Load

    Hello,

    I have been trying to do this just about everyway possible and I can't seem to figure it out.

    I want to have a parameter value that is an "Enter Section" and for it to filter my information on the Form Open or OnLoad. I have tried on macro, VB, and just creating a Syntax in the Property Sheet.

    I know there are afew ways to do this but I would like to know how ot do it in VB just to learn alittle more about it. Thank you for your help, or if your just reading the thread, thank you for your time ([Emoticon] = "Smile")

  2. #2
    Join Date
    Jan 2009
    Location
    Kerala, India
    Posts
    183
    You can pass a filter condition while opening a Form through VBA Command like the example below:

    Code:
    DoCmd.OpenForm "Employees",acNormal,,"[EmployeeID] = 123"
    The Employee Form will open with the Employee record of Employee Code 123 filtered.

    For mode details refer the article: Form/Report Open Arguments
    www.MsAccessTips.com (Learn MS-Access Tips & Tricks)
    Learn Advanced MS-Access Programming with sample VBA Code.

    All responses are based on Access 2003/2007

  3. #3
    Join Date
    Oct 2011
    Location
    USA
    Posts
    13

    Smile Figured it out

    I went looking for answers and finally found them on

    open form to specific record or create new record - Microsoft Access / VBA

    What I needed to do was do the VB Code:

    DoCmd.OpenForm "OwnerDataScreen", , , "[Section]=" & "Me.Section"

    Me.FilterOn = True

    What I am guessing is that the "[Section]=" is where it is looking for the information and the " & "Me.Section" is just asking what it wants to display as the title of the Parameter box. If anyone has something that could help me with understanding this Code more please let me in on the gouge. God bless.

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    effectively the
    "[EmployeeID] = 123"
    in
    DoCmd.OpenForm "Employees",acNormal,,"[EmployeeID] = 123"
    is the filter and is analagous to the 'WHERE; subclause in SQL
    its saying WHERE the EmployeeID = 123
    or Me.filter = "[EmployeeID] = 123"

    you need to encapsulate string literals with a ' or "

    so in your case, assuming you have a column called 'Enter Section' then you need
    "[Enter Section] = 897098709" ...if enter section is numeric
    "[Enter Section] = 'iuyoiuyoiu'" ...if enter section is string / text

    the me.section would refer to a control on your form called section.... which obviously is pants for your requirements as the control would have no value when the form is loading

    BTW itds easier to read the SQL if you avoid includign spaces in column / table names. using a space means the column name must be enclosed in square brackets
    whether you choose to run the words together: entersection, and use CamelCase: EnterSection
    OR use an underscore: enter_section, and use CamelCase: Enter_Section is upto you.
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Oct 2011
    Location
    USA
    Posts
    13

    Thumbs up

    I kinda lost you at the Assuption that I have a column named "Enter Section"

    I have a Column named "Section" and I have a tab in my form that I want it to filter to so that it is the only one looked up. there is only 1 Section for each of the records that can be in the Parent link table. I have figured it our for the most part, I just wish that I could understand what I am putting in the VB module to make it work the way it does so I can continue to use to use it on other Databases and helping others if they ever have VB questions.

    My Parameter box now asks me for "Me.Section" however I would like it to Say "Enter_Section". the filter works fine I just want to pretty it up :P. Thank you for the answer though, I am just very new at the whole VB and SQL Code stuff.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •