Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Jul 2003
    Location
    Cincinnati, Ohio
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Use value from form to construct *like query (XP)

    I have a form frmSelectProject with a combo box on it cmbRegionCode. The combo box presents a list of four character region codes. I have a query called qryByRegion. Within the query I have a ProjectName field. I would like to use the region code selected from cmbRegionCode on frmSelectProject to create a *like statement criteria for the ProjectName field within the query (The project names all use the four character region codes as a prefix) to pull a list of all projects for that region. I have tried [Forms]![frmSelectProject].[*cmbRegionCode*] as the criteria for ProjectName but no records return when I run the query. Thank you for any help. -scott

  2. #2
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Use value from form to construct *like query (XP)

    You could do this a couple of ways:

    One way would be to add the Project Name to the query again as Left(ProjectName,4) so only the first 4 characters are returned.
    Then filter it as [Forms]![frmSelectProject].[cmbRegionCode] - you won't even need to use "like".

    HTH
    Regards,

    Gary
    (It's been a while!)

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Use value from form to construct *like query (XP)

    Hi Scott, you must concatenate the wildcards with the reference to the form; you cannot include the wildcards in the reference itself. Try this:

    <code>LIKE [Forms]![frmSelectProject].[cmbRegionCode] & "*"</code>

    if the region codes are prefixes as you wrote, or if the region code can be any part of the project name:

    <code>LIKE "*" & [Forms]![frmSelectProject].[cmbRegionCode] & "*"</code>

  4. #4
    2 Star Lounger
    Join Date
    Jul 2003
    Location
    Cincinnati, Ohio
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Use value from form to construct *like query (XP)

    It worked! Thank you Gary & Hans. - scott

Posting Permissions

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