Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2003
    Posts
    34

    Unanswered: Passing a parameter into a query from one of two forms

    The simplest explanation of my problem is this:

    I have three forms, frm1Buyer, frm2Pick, and frm3.

    frm1Buyer is used to enter Buyer information into tblBuyer; the primary key is BuyerID.

    frm2Pick is used to call up specific Buyer records from tblBuyer, also using BuyerID.

    Both of them have a button that takes you to frm3 (there is no other way to get to frm3 for the user).

    I want to be able to pass the BuyerID from <i>EITHER</i> frm1Buyer or frm2Pick, depending upon which one is open.

    I don't think I can do this with a parameter query, because it can't store the value. I've been trying to think of a way to do this with an sql query created in VB, and I'm stumped.

    Is it possible to run VB code upon the Click Event of the "exit" button for frm1Buyer and frm2Pick, before the form closes, that changes the criteria of the BuyerID field in a stored query and then runs the query? That would leave the data behind for frm3 to pull from.

    Any other ideas would be appreciated.

    Thanks!

  2. #2
    Join Date
    Nov 2003
    Location
    LONDON
    Posts
    238

    Re: Passing a parameter into a query from one of two forms

    Originally posted by Ewin
    The simplest explanation of my problem is this:

    I have three forms, frm1Buyer, frm2Pick, and frm3.

    frm1Buyer is used to enter Buyer information into tblBuyer; the primary key is BuyerID.

    frm2Pick is used to call up specific Buyer records from tblBuyer, also using BuyerID.

    Both of them have a button that takes you to frm3 (there is no other way to get to frm3 for the user).

    I want to be able to pass the BuyerID from <i>EITHER</i> frm1Buyer or frm2Pick, depending upon which one is open.

    I don't think I can do this with a parameter query, because it can't store the value. I've been trying to think of a way to do this with an sql query created in VB, and I'm stumped.

    Is it possible to run VB code upon the Click Event of the "exit" button for frm1Buyer and frm2Pick, before the form closes, that changes the criteria of the BuyerID field in a stored query and then runs the query? That would leave the data behind for frm3 to pull from.

    Any other ideas would be appreciated.

    Thanks!
    You can use Docmd.OpenForm to open the third form with a Where clause (don't use the word Where though). See the help file for the full syntax of the OpenForm method.

    You could also set the formfilter of the form you wish to open or you could set the recordsource of the form. If you have Access 2000 and above you could use the form recordset to attach the data.

    And there are many other ways as well!

  3. #3
    Join Date
    Oct 2003
    Posts
    34
    I forgot to mention; frm3 is an unbound form. How do I use the WHERE condition if I'm not calling up a specific record?

    I only need to pull in the BuyerID because every query that I use to populate the other boxes depends upon it.

  4. #4
    Join Date
    Nov 2003
    Location
    LONDON
    Posts
    238
    Originally posted by Ewin
    I forgot to mention; frm3 is an unbound form. How do I use the WHERE condition if I'm not calling up a specific record?

    I only need to pull in the BuyerID because every query that I use to populate the other boxes depends upon it.
    You can use the OpenArgs property of the OpenForm method to pass in any value you want. The OpenArgs property of the form can be retrieved at any time eg Me("txtBuyerID").Value = Me.OpenArgs

  5. #5
    Join Date
    Oct 2003
    Posts
    34
    Ah-ha! The OpenArgs is working like a charm, and I can put the code for it on both forms. Thank you!

Posting Permissions

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