Welcome to SPN

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

Sign Up Now!

Dynamic query parameters

Discussion in 'Information Technology' started by Bob, Nov 5, 2005.

  1. Bob

    Bob
    Expand Collapse
    Guest

    Got controls with a Rowsource using a select statement, the where clause of
    the select statement should use a variable existing in code.
    Whats the syntax for writing this
    Quick sample:

    Dim Myvar as string
    Myvar = "abcd"
    Say the variable setting above was public in scope and declared well before
    the form using it is called.
    select * from mytable where myfield = "abcd" what I would think to be the
    final result sql statement

    What should I write in the Rowsource of the control? I dont want parameter
    question boxes to pop up. I just want the control to gran the variable and
    use it automatically.


    Thanks for any help

    Bob
     
  2. Loading...

    Similar Threads Forum Date
    India India's family dynamic undergoing a change Breaking News Feb 7, 2011
    Dynamic Morality Essays on Sikhism Jul 21, 2004
    Query about Jhatka Meat by Shooting in Head Sikh Sikhi Sikhism Aug 26, 2011
    Who is a sikh? A non sikh friend's query!! Sikh Sikhi Sikhism Apr 30, 2010
    General Query Hard Talk Sep 4, 2008

  3. Wayne Morgan

    Wayne Morgan
    Expand Collapse
    Guest

    You could rewrite the Row Source using code.

    Me.MyControl.RowSource = "select * from mytable where myfield = """ & MyVar
    & """"

    This will concatenate in the value of MyVar and place double quotes around
    it.

    You could also place the value of the variable in a table created just for
    this purpose then the SQL statement could find it using a DLookup function.

    --
    Wayne Morgan
    MS Access MVP


    "Bob" <bdufour@sgiims.com> wrote in message
    news:%23vJPHaW4FHA.2640@TK2MSFTNGP09.phx.gbl...
    > Got controls with a Rowsource using a select statement, the where clause
    > of the select statement should use a variable existing in code.
    > Whats the syntax for writing this
    > Quick sample:
    >
    > Dim Myvar as string
    > Myvar = "abcd"
    > Say the variable setting above was public in scope and declared well
    > before the form using it is called.
    > select * from mytable where myfield = "abcd" what I would think to be the
    > final result sql statement
    >
    > What should I write in the Rowsource of the control? I dont want parameter
    > question boxes to pop up. I just want the control to gran the variable and
    > use it automatically.
    >
    >
    > Thanks for any help
    >
    > Bob
    >
    >
     

Share This Page