Results 1 to 2 of 2
  1. #1
    lccrews is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Location
    Los Angeles
    Posts
    194

    How do I populate a textbox with information related to a record I have selected?

    I have a form with (4) subforms on it displaying ingredients. There is one field [Item] that all (4) subforms share in common. What do I need to do in order to make this happen:



    1. click on record in subform (the [Item] field)
    2. look up that Item on tbl_BulkItems and display [Descr] in Textbox1

    So when a user clicks [Item] on any record in the datasheet, it's description is populated in a textbox. Any help is appreciated!

    Update:

    I figured it out. Using the below code, you can set the value of a textbox on the main form to the value of the query in VBA. Here it is:
    Code:
    Private Sub Item_Click()
    Dim rst As DAO.Recordset
    Dim sSQL As String
    
    
    sSQL = "SELECT tbl_BulkItems.Descr FROM tbl_BulkItems WHERE (((tbl_BulkItems.Item)='" & Me.Item & "'));"
    
    
    Set rst = CurrentDb.OpenRecordset(sSQL)
    
    
    Description = rst![Descr]
    
    
    Forms!frm_WhereUsed!Item = Description
    
    rst.Close
    Set rst = Nothing
    
    
    End Sub
    Last edited by lccrews; 06-28-2018 at 02:57 PM. Reason: Solved

  2. #2
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,165
    This is assuming your [Item] field is a unique identifier in tbl_BulkItems.

    Open your subform and right click your item field, then click "Build Event..." and get into the VBA editor and add something like this to the OnClick event (may need to adapt to your specific needs):

    Code:
    Me.Parent!Textbox1.Value = DLookUp("[Descr]", "tbl_BulkItems", "[Item]=" & Me.Item )
    You'll need to add this code to the [Item] field control for each distinct subform.

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

Similar Threads

  1. Replies: 1
    Last Post: 04-29-2017, 12:46 PM
  2. Replies: 3
    Last Post: 10-22-2014, 09:44 AM
  3. Replies: 8
    Last Post: 06-26-2014, 08:52 AM
  4. Replies: 2
    Last Post: 08-21-2013, 09:39 AM
  5. Replies: 12
    Last Post: 04-18-2011, 08:52 AM

Tags for this Thread

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