Results 1 to 4 of 4
  1. #1
    ngruson is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2010
    Posts
    6

    Form with parameterized query

    Hi,

    I have a (detail)form which has a parameterized query as its recordsource. This form should be opened when clicking a button on the mainform. The value of the parameter should be the ID of the current record on the mainform.


    How can I fill the parameter with the correct value and then open the detailform?

    Thanks in advance,
    Nils

  2. #2
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    Hi,

    I presume the [ID] field makes part of your query. So just put as the selection criterium on this ID field:

    Forms![Name form]![Name ID field on the form]

  3. #3
    ngruson is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2010
    Posts
    6
    What I have now is the following:

    Code:
    Public Sub OpenForm(frm As String, Optional qry As String)
        Subform.SourceObject = frm
        If qry <> "" Then
            Subform.Form.RecordSource = qry
        End If
        Subform.Visible = True
    End Sub
    This code is called in the main form. When a button in the mainform is clicked, the subform control is bound. When a detail form needs to be shown, the qry parameter is set with the right query to show one record (select * from tasks where id = 1).
    Is this optimal? Now I rebuild the query everytime. Isn't there a way to bound a form to a parameterized query in designtime and set the parameter of this query in runtime?

  4. #4
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    Hi,

    if the relations are put right you can bind your subform to the main form using the Primary and Foreign key fields in the "Link Master fields" and "Link child fields" property of your subform control. When the relations are OK, Access wxill even propose these fields as binding fields by default.

    greetings
    NG

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

Similar Threads

  1. Count distinct records in parameterized query
    By SilverSN95 in forum Access
    Replies: 5
    Last Post: 07-27-2010, 09:31 AM
  2. Query to only show a value in a form from a query
    By cwwaicw311 in forum Queries
    Replies: 28
    Last Post: 03-27-2010, 02:31 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