Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2005
    Posts
    240

    Unanswered: Add Parameter to QueryDef

    Hi all,

    Simple question. I have a QueryDef running on a form, but is is possible to add more parameters to the existing ones by code, if so how?

    This is what I have:

    Code:
    Set QDef = CurrentDb.QueryDefs("qrySearchRECEPE")
     
    QDef.Parameters("[Forms]![frmSearch]![txtEmpName]").Value = [Forms]![frmSearch]![txtEmpName]
    QDef.Parameters("[Forms]![frmSearch]![txtTown]").Value = [Forms]![frmSearch]![txtTown]
    QDef.Parameters("[Forms]![frmSearch]![txtCounty]").Value = [Forms]![frmSearch]![txtCounty]
    QDef.Parameters("[Forms]![frmSearch]![txtCountry]").Value = [Forms]![frmSearch]![txtCountry]
    QDef.Parameters("[Forms]![frmSearch]![txtPCode]").Value = [Forms]![frmSearch]![txtPCode]
    QDef.Parameters("[Forms]![frmSearch]![cmboBArea]").Value = [Forms]![frmSearch]![cmboBArea]
    QDef.Parameters("[Forms]![frmSearch]![chkOnStop]").Value = [Forms]![frmSearch]![chkOnStop]
    QDef.Parameters("[Forms]![frmSearch]![chkNPTC]").Value = [Forms]![frmSearch]![chkNPTC]
    QDef.Parameters("[Forms]![frmSearch]![txtNoEmps]").Value = [Forms]![frmSearch]![txtNoEmps]
     
    Set rst = QDef.OpenRecordset
     
        stDocName = "frmEmployers"
        If rst.EOF Then
            MsgBox "No employers found.  Please add this employer.", vbOKOnly, "RECEPE"
            DoCmd.OpenForm "frmEmpMenu"
            strCheck = "No Records"
        End If
    I'm trying to get around a problem I am having regarding a checkbox value, where I would like to show all records including the checked records when the value is false, but just the checked records when the value is true.

    I thought of possibly adding a new parameter to the code without adding a parameter in the query, so I could return all the records.
    Would something like this work?

    Code:
    If Me!chkT2G = True Then
       ' Add new parameter here, set to true
    End If
    Thanks
    Last edited by KevCB226; 11-06-06 at 06:55.

  2. #2
    Join Date
    Aug 2002
    Location
    Northampton, England
    Posts
    266
    There is a good example here.

    http://support.microsoft.com/kb/210242/en-us

Posting Permissions

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