Results 1 to 4 of 4
  1. #1
    desk4tbc is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2011
    Posts
    29

    Search for a field in a table and return a seperate field in the same record

    Hi guys,

    I was hoping you could help me with a problem. I'm trying to search for a particular string that the user inputs against all records in a table and then use the first search result to return data in another field in the same record.

    I'm trying to use sql to do the search but I don't know how to hold the records that match the search criteria and return information from a separate field.

    Code:
    DoCmd.RunSQL "SELECT PatientInsurance.[Patient ID] FROM PatientInsurance WHERE [Contact] LIKE '" & strSearch & "';"
    Where PatientInsurance is a table and the contact is a field within that table. I want to return the field [Patient ID] from the first record found in that sql query. How would I go about storing that data in a variable?



    EDIT: Changed the sql statement.
    Last edited by desk4tbc; 08-25-2011 at 06:31 PM. Reason: SQL

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Look at using DLookup() instead.

  3. #3
    desk4tbc is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2011
    Posts
    29
    Thanks again Rural. It hit me this morning that it would be an easier method rather than to set up a data array. Its what I get for staring at vba for 7 hours straight.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Glad we could help.

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

Similar Threads

  1. Button to search table with any field in form
    By sephiroth2906 in forum Forms
    Replies: 3
    Last Post: 04-19-2011, 11:17 AM
  2. Return field value based on the same table
    By snoopy2003 in forum Queries
    Replies: 2
    Last Post: 03-05-2011, 02:45 AM
  3. Replies: 1
    Last Post: 03-01-2011, 04:03 PM
  4. Replies: 1
    Last Post: 05-17-2010, 12:21 PM
  5. Replies: 1
    Last Post: 02-05-2009, 04:53 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