Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2014
    Posts
    3

    Unanswered: Lookup from a table with the ability to add new data

    I'm not entirely sure how to word this, I've tried a few google searches to no avail so I guess it can't hurt to ask here.

    I'm looking to create a form for inputting an order. I want to select the product that the order is related to from a lookup, but be able to -add- the product if it doesn't already exist in the lookup list.

    For example:
    I have an order, I go to input it. The product it's related to is an iPhone 4S, 16GB. The iPhone 4S isn't in my table already, I know this because I've looked through the lookup list. I want to be able to select the iPhone 4S for future orders (to avoid duplicate data) without having to add it manually in the tables.

    Any advice? Sorry if I'm not making what I'm asking clear.

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Not knowing the name of the table, nor how it's organized, this example uses generic names, replace them by the actual ones in your application.
    Code:
    If IsNull(DLookup("Product", "TableName", "Product = 'iPhone 4S')) Then
        strSQL = "INSERT INTO TableName ( Product ) Values ( 'iPhone 4S');"
        Currentdb.Execute strSQL, dbFailOnError
    End If
    Have a nice day!

  3. #3
    Join Date
    Mar 2014
    Posts
    3
    Quote Originally Posted by Sinndho View Post
    Not knowing the name of the table, nor how it's organized, this example uses generic names, replace them by the actual ones in your application.
    Code:
    If IsNull(DLookup("Product", "TableName", "Product = 'iPhone 4S')) Then
        strSQL = "INSERT INTO TableName ( Product ) Values ( 'iPhone 4S');"
        Currentdb.Execute strSQL, dbFailOnError
    End If
    I'm sure this works in one manner, but the issue is it's too specific. The input won't always be an iPhone 4S. I'll fiddle with it and see if I can figure it out.

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Of course ! It was just an example. Use a variable instead of a litteral.
    Have a nice day!

Posting Permissions

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