Results 1 to 8 of 8
  1. #1
    lacigol is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    14

    reference a field in unbound subform with double click event

    Brief: I want to double click a record in an unbound subform (sfPartsList) and it be added to another subform (sfProject). I am open to alternative solutions.



    I have a text box (txtSearch) in the main form that filters the records (parts) of an unbound subform (sfPartsList) on keyup via sql. The record count rarely equals one because the search (sql) spans multiple fields within the PartsList table with a short search string. I want to be able to populate a second subform (sfProject) with records that a user double clicks on in sfPartsList, essentially choosing parts for a project after a search and double click. A bill of materials solution?

    I do not remember how to reference records in a subform in order to copy or address their fields to another table or control.

  2. #2
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Are both subforms from the same form?


    Sent from my iPhone using Tapatalk

  3. #3
    lacigol is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    14
    Yes.567890

  4. #4
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    Maybe you want to use the RecordsetClone property to copy over the records, but I'm not sure because you say the form isn't bound to anything, yet it seems to have records. The only other way I can think of how this is possible is that you went to all the trouble to loop through all the fields of a record set and assigned them to the form controls. In that case, you ought to have a usable recordset?? Maybe by "unbound sub form" you mean that it's not linked to the main form...
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    lacigol is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    14
    Here's what populates my sfPartsList.

    Code:
    Private Sub txtSearch_KeyUp(KeyCode As Integer, Shift As Integer)
      
      Dim sql, search As String
    
      // replace ' with '' and spaces with *
      search = Replace(Replace(txtSearch.Text, "'", "''"), " ", "*")
      
      sql = "SELECT * from PartsList " _
                & "WHERE sheet like '*" & search & "*' " _
                & "OR vendor like '*" & search & "*' " _
                & "OR desc like '*" & search & "*' " _
                & "OR cat like '*" & search & "*' " _
                & "OR subcat like '*" & search & "*'" _
                & "OR partNum like '*" & search & "*' "
      
      Me.sfPartsList.Form.RecordSource = sql
    
    
    End Sub
    So it's updated every keypress to narrow down search results. I might be searching for a 2'x2' something and it may give me several records containing 2'x2', but when I double click on one of those records I want it to add or append that record to another subform. I just can't recall a way to reference the record double clicked on...

  6. #6
    lacigol is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    14
    So I press ESC when a wizard is triggered (like putting a subform on a form). I decided to go through the wizard to try a different approach.

    Although the subform wizard adds a "PartsList subform" to Access Objects (small frown), the double click event is available in that subform.

    I saw a thread about someone wanting to double click a record to open that record in a new form and their reference was simple enough. Test with msgbox below:

    Code:
    Private Sub Form_DblClick(Cancel As Integer)
      'from https://bytes.com/topic/access/answers/192500-double-click-record-subform-open-record-new-form
      'DoCmd.OpenForm "NameOfDifferentForm",,,"[OrderDetailsID] = " & Me!OrderDetailsID
      MsgBox Me!ID
      
    End Sub

  7. #7
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    so you figured out how to do what you wanted?
    edit: ignore - just noticed you had marked this as solved.

  8. #8
    lacigol is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    14
    I did not, but I did find a satisfying work-around.

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

Similar Threads

  1. Replies: 6
    Last Post: 02-28-2017, 09:33 AM
  2. Replies: 3
    Last Post: 07-22-2015, 03:45 AM
  3. Opening records via Double-Click event on a search form.
    By IncidentalProgrammer in forum Programming
    Replies: 4
    Last Post: 11-21-2014, 03:47 PM
  4. Replies: 3
    Last Post: 08-21-2014, 07:42 PM
  5. On Double Click go to Subform
    By Theremin_Ohio in forum Access
    Replies: 2
    Last Post: 03-30-2011, 08:03 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