Results 1 to 12 of 12
  1. #1
    Bazsl is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2016
    Posts
    47

    How insert field value from current record in lookup field SQL?


    I need to use the value from the Customer Number field in the current record in the WHERE clause of the SQL statement for a lookup field. The SQL is:

    SELECT [Event].[Event Number], [Event].[Event Name] FROM Event WHERE [Event].[Customer Number] = <value from customer number field in current record> ORDER BY [Event Name];

    What do I put in the WHERE clause in place of <value from customer number field in current record> to get the value from the Customer Number field in the current record? Thanks.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    If you are really using a "LookUp Field" then you should read this: http://access.mvps.org/access/tencommandments.htm

  3. #3
    Bazsl is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2016
    Posts
    47
    Thanks for the reference, however, assuming that I do have a good reason for providing the user with a combo box from which to select a value, is there a way to use the value from a field in the current row in the SQL statement in the Row Source property?

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Is it a "LookUp Field"? If so, the value you see is not really there.

  5. #5
    Bazsl is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2016
    Posts
    47
    I think we are having a semantic problem. I open a table in Design View. I click on a field. In the bottom pane I click on the Lookup tab. In the Row Source field on the Lookup tab is a SQL statement. I want to use the value from a field in the current row of the table as a parameter in that SQL statement. I hope that is clear.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    That is a real "Lookup Field". Having a ComboBox on a form is just fine and works as you would expect. Having them in a record can be a nightmare. Sorry.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    If it's the ID you want anyway, how about:

    SELECT [Event].[Event Number], [Event].[Event Name] FROM Event WHERE [Event].[Customer Number] = Forms!FormName.ComboName ORDER BY [Event Name];
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    Bazsl is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2016
    Posts
    47
    Thanks Paul. I assume that Forms!FormName.ComboName will only work with a combo box on a form and not with a lookup at the table level. Is that correct? If so, I can live with that.

  9. #9
    Bazsl is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2016
    Posts
    47
    RG, The problem with using lookups only in forms is that someone may, for whatever reason, edit the tables directly and I would like to make that as easy and safe as possible. I should mention that this is not an app. This database if for a very small not-for-profit organization. It will be used by people who can find the on/off switch on their PCs but not much more. There will be no programming. There will be no macros if I can possibly avoid it because there will not be anyone capable of maintaining macros or code. The lookups and RI declarations will be the most sophisticated part of this database. If table level lookups are so buggy that data corruption is possible I will not use them but otherwise I am inclined to do so.

  10. #10
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I to agree with RG.
    And users should never be allowed to edit the tables directly.

  11. #11
    Bazsl is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2016
    Posts
    47
    There is no way to prevent a user from editing tables directly in this situation. You are the second person that is opposed to table level lookups. What is the problem with table level lookups? Just curious.

  12. #12
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    I tried this search in google and got several responses:

    ms access how to prevent the user from interacting directly with tables

    Good luck

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

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2015, 01:45 PM
  2. Replies: 2
    Last Post: 01-16-2015, 04:22 PM
  3. Replies: 2
    Last Post: 03-05-2014, 05:37 PM
  4. Replies: 2
    Last Post: 08-02-2012, 01:47 PM
  5. Replies: 2
    Last Post: 06-13-2012, 06:00 PM

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