Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

VBA--click a button to open a TABLE and only show conditioned records ?

Discussion in 'Information Technology' started by Martin, Oct 29, 2005.

  1. Martin

    Martin
    Expand Collapse
    Guest

    In a FORM, I want to create a button, when I click this button, the Access
    will open TABLE "Customer Inf", with the condition that field "customer
    name"="Martin Lee". Also, I want,below the selected "Martin Lee" records, it
    has a blank line for which the users to enter a new record here.

    How should the VBA code should be ?


    BTW, if it is a QUERY (instead of a FORM), how should the VBA code be, to
    filter up "customer name"="Martin Lee"?


    Thanks!


    Martin
     
  2. Loading...

    Similar Threads Forum Date
    Should SPN Keep the 'Like' Button? SPN Poll Hard Talk May 17, 2013

  3. Dirk Goldgar

    Dirk Goldgar
    Expand Collapse
    Guest

    "Martin" <lajitong888@21cn.com> wrote in message
    news:%23uqhgS92FHA.1476@TK2MSFTNGP10.phx.gbl
    > In a FORM, I want to create a button, when I click this button, the
    > Access will open TABLE "Customer Inf", with the condition that field
    > "customer name"="Martin Lee". Also, I want,below the selected "Martin
    > Lee" records, it has a blank line for which the users to enter a new
    > record here.
    >
    > How should the VBA code should be ?


    I don't recommend letting your users work directly in the tables. For
    one thing, you have much less control. Why not create a continuous form
    (or even a datasheet form) bound to this table; then you can open it
    and supply the where-condition at the same time via the DoCmd.OpenForm
    method.

    If you insist on opening the table directly, there's no way to filter it
    in the same statement that opens it. However, you can filter it in the
    very next statement, like this:

    Dim strCustomerWanted As String

    strCustomerWanted = "Martin Lee"

    Docmd.OpenTable "Customer Inf"
    DoCmd.ApplyFilter , "[customer name]=" & _
    Chr(34) & strCustomerWanted & Chr(34)

    Note the comma that immediately follows the name of the ApplyFilter
    method. That's critical, because it distinguishes the optional
    "FilterName" argument (which we're not using) from the "WhereCondition"
    argument (which we are using).

    > BTW, if it is a QUERY (instead of a FORM), how should the VBA code
    > be, to filter up "customer name"="Martin Lee"?


    I'm not sure I understand this question.

    --
    Dirk Goldgar, MS Access MVP
    www.datagnostics.com

    (please reply to the newsgroup)
     
  4. Martin

    Martin
    Expand Collapse
    Guest

    Thanks, and I have several question base on your answer. New posted.
    "Dirk Goldgar" <dg@NOdataSPAMgnostics.com> дÈëÏûÏ¢ÐÂÎÅ:e5C1XI$2FHA.1276@TK2MSFTNGP09.phx.gbl...
    > "Martin" <lajitong888@21cn.com> wrote in message
    > news:%23uqhgS92FHA.1476@TK2MSFTNGP10.phx.gbl
    >> In a FORM, I want to create a button, when I click this button, the
    >> Access will open TABLE "Customer Inf", with the condition that field
    >> "customer name"="Martin Lee". Also, I want,below the selected "Martin
    >> Lee" records, it has a blank line for which the users to enter a new
    >> record here.
    >>
    >> How should the VBA code should be ?

    >
    > I don't recommend letting your users work directly in the tables. For
    > one thing, you have much less control. Why not create a continuous form
    > (or even a datasheet form) bound to this table; then you can open it
    > and supply the where-condition at the same time via the DoCmd.OpenForm
    > method.
    >
    > If you insist on opening the table directly, there's no way to filter it
    > in the same statement that opens it. However, you can filter it in the
    > very next statement, like this:
    >
    > Dim strCustomerWanted As String
    >
    > strCustomerWanted = "Martin Lee"
    >
    > Docmd.OpenTable "Customer Inf"
    > DoCmd.ApplyFilter , "[customer name]=" & _
    > Chr(34) & strCustomerWanted & Chr(34)
    >
    > Note the comma that immediately follows the name of the ApplyFilter
    > method. That's critical, because it distinguishes the optional
    > "FilterName" argument (which we're not using) from the "WhereCondition"
    > argument (which we are using).
    >
    >> BTW, if it is a QUERY (instead of a FORM), how should the VBA code
    >> be, to filter up "customer name"="Martin Lee"?

    >
    > I'm not sure I understand this question.
    >
    > --
    > Dirk Goldgar, MS Access MVP
    > www.datagnostics.com
    >
    > (please reply to the newsgroup)
    >
    >
     

Share This Page