Results 1 to 11 of 11
  1. #1
    dniezby is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2013
    Posts
    183

    Query Designer with Field Value

    Is it possible to create a query in the designer that looks for a value from a Form control?



    For example, I have two tables:

    tblContacts , tblCampaigns

    I have a form frmCampaigns . This will be tracking my marketing campaigns. On the form is a is a field name that I will be turning into a button. When someone clicks that button I want it to open a query result.

    It should list all of the contacts from my contact table that have the same campaign ID as the campaign form I'm on.

    I hope I didn't just confuse everyone.

    I did make this query in the query designer and it works but I already have the WHERE set to 1...When it's on the form it needs the WHERE set to Me!ID of the current record.

    Can I do this from the designer or do I have to create it in VBA code.

    Here is the sqlview of the query from the designer.

    Code:
    SELECT tblContacts.FirstName, tblContacts.LastName, tblCampaigns.CampaignCode
    FROM tblCampaigns INNER JOIN tblContacts ON tblCampaigns.ID = tblContacts.Campaign_ID
    WHERE (((tblCampaigns.ID)= 1));

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Try:
    Code:
    SELECT tblContacts.FirstName, tblContacts.LastName, tblCampaigns.CampaignCode
    FROM tblCampaigns INNER JOIN tblContacts ON tblCampaigns.ID = tblContacts.Campaign_ID
    WHERE (((tblCampaigns.ID) = Forms.frmCampaigns.ID));

  3. #3
    dniezby is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2013
    Posts
    183
    Quote Originally Posted by RuralGuy View Post
    Try:
    Code:
    SELECT tblContacts.FirstName, tblContacts.LastName, tblCampaigns.CampaignCode
    FROM tblCampaigns INNER JOIN tblContacts ON tblCampaigns.ID = tblContacts.Campaign_ID
    WHERE (((tblCampaigns.ID) = Forms.frmCampaigns.ID));
    Cool, I'll give this a shot. Thanks. I didn't know I could put that criteria there. Thank you very much.

  4. #4
    dniezby is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2013
    Posts
    183
    That didn't work. It just keeps asking me for the campaign ID. It's not taking it from the form.

  5. #5
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    I would have thought this syntax was required
    Forms!frmCampaigns.ID));
    Plus, ID is the name of the form control and not the name of the field the control is bound to? Or have you let it be named Text11 or some such default?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,543
    Quote Originally Posted by dniezby View Post
    That didn't work. It just keeps asking me for the campaign ID. It's not taking it from the form.
    What is the name of the control on the form which shows the ID.
    If it is CampaignsID then the where clause would need to be:
    WHERE (((tblCampaigns.ID) = Forms.frmCampaigns.CampaignsID));
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  7. #7
    dniezby is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2013
    Posts
    183
    Quote Originally Posted by Bob Fitz View Post
    What is the name of the control on the form which shows the ID.
    If it is CampaignsID then the where clause would need to be:
    WHERE (((tblCampaigns.ID) = Forms.frmCampaigns.CampaignsID));
    OMG - Found the problem. I was using frmCampaigns and it's actually singular for the form name. frmCampaign also I changed the CampaignsID to just = ID

    Now it shows me the correct contact information for everyone that falls under that campaign data.

    Thanks.

  8. #8
    dniezby is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2013
    Posts
    183
    Now that it works....Is there a way for me to present the information in a better looking manner? I know I can create a form which will look ideal and pleasant to my user but, will it keep the information it needs to present in a form.

    For example, right now it looks at the Control "ID" on my form and says to present all the contacts where Contact_ID = ID... Will that follow over to a form or is it now time to move to the Programming forum?

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    In order for that query to work as you want, the frmCampaign needs to be open. No need to switch forums. Right here will be just fine.

  10. #10
    dniezby is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2013
    Posts
    183
    Got it working using the information you provided. Thank you.

  11. #11
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Thanks for posting back with your success and solution.

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

Similar Threads

  1. Replies: 3
    Last Post: 08-04-2016, 01:01 PM
  2. Replies: 6
    Last Post: 09-19-2012, 02:32 PM
  3. Replies: 0
    Last Post: 11-21-2011, 01:33 PM
  4. Replies: 0
    Last Post: 02-03-2011, 05:40 AM
  5. Replies: 1
    Last Post: 09-19-2006, 11:07 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