Results 1 to 12 of 12
  1. #1
    thaBadfish is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    6

    Subform Data Entry Button - Search Button

    I have a form [Search Results] that is set to pull entries from table [Drawings] in a continuous form. I added a button to call up a data entry form [frmDrawingDataEntry] which is linked to each table entry via [ID]. I have a tempvar which links the data entry form to the search results form via ID, and each button brings up the correct corresponding data entry form, where I can edit fields, save, move to previous or next entries, or create a new entry.

    The issue occurs after I bring [Search Results] into a new form [Drawing Search] as a subform. [Drawing Search] displays [Search Results] correctly, including each button (which also correctly brings up the corresponding data entry form). However, the point of this form is the keyword search feature that I included to filter the subform [Search Results]. The search feature consists of a text box "Keywords" and a button "SearchButton". The button has an on click event which evokes VBA as such:
    Code:
    Option Compare Database
    Option Explicit
    
    
    Private Sub SearchButton_Click()
        Dim SQL As String
        
        SQL = "SELECT [Drawings].[Project Description], [Drawings].[Drawing Author], [Drawings].[Drawing Number], [Drawings].[Drawing Name], [Drawings].[Drawing Date], [Drawings].[Storage Location] FROM [Drawings] WHERE [Project Description] LIKE '*" & Me.Keywords & "*' OR [Drawing Author] LIKE '*" & Me.Keywords & "*' OR [Drawing Number] LIKE '*" & Me.Keywords & "*' OR [Drawing Name] LIKE '*" & Me.Keywords & "*' OR [Drawing Date] LIKE '*" & Me.Keywords & "*' OR [Storage Location] LIKE '*" & Me.Keywords & "*' ORDER BY [Drawings].[Project Description]; "
        
        Me.SearchResults.Form.RecordSource = SQL
        Me.SearchResults.Form.Requery
        
    
    
    End Sub
    [SearchResults] is the subform on the main form [Drawing Search] with a source object of the form [Search Results] (I probably could've named those in a less confusing manner). So if you followed me so far, I have a search feature which requeries a subform on a main form. The search feature displays the correct results, however once I click the button which calls up the data entry form (mentioned previously) I get a "Type Mismatch" error referring to the macro I have set up for assigning a tempvar linking the data entry form to the search results via [ID]. Basically, the data entry form has a on load event which states:
    Code:
    If Not IsNull([TempVars]![VarDrawingID]) Then
         SearchForRecord
              Object Type: Form
              Object Name: frmDrawingDataEntry
              Record: First
              Where Condition = ="[ID]=" & [TempVars]![VarDrawingID]
    End If
    The subform button looks like this:
    Code:
    SetTempVar
         Name: VarDrawingID
         Expression =[Forms]![Drawing Search]![SearchResults].[Form]![ID]
    
    OpenForm
         Form Name: frmDrawingDataEntry
         View: Form
         Filter Name:
         Where Condition:
         Data Mode: Edit
         Window Mode: Dialog
    So once again, this button brings up the correct [frmDrawingDataEntry] until I search via the VBA I referenced earlier, which gives me the "Type Mismatch" error.

    I'm very new to access, and I'm just trying to create a simple, clean database that will allow my client to quickly search his drawing records and find the storage location. I have linked the file, and any help is greatly appreciated.
    If you use the linked file, the main form [Drawing Search] will open. If you click the button under any entries "EDIT" field, the [frmDrawingDataEntry] form will pop up correctly. If you then type anything into the keyword search (such as "CANCER") the results will correctly filter, but the "EDIT" button will no longer work.

    Link to file: (733KB)
    https://onedrive.live.com/redir?resi...t=file%2caccdb



    Thanks

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Unhide the ID field (which the edit button relies on) and perform your search.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    thaBadfish is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    6
    Ok, that gives some more insight into what's going wrong, but I'm still unsure how to fix it.
    So with the ID field visible in the subform, I see that once I search the ID fields change to "#Name?". I'm not yet sure why, but the ID field breaks once the VBA search occurs.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Because the ID field isn't here:

    SQL = "SELECT [Drawings].[Project Description], [Drawings].[Drawing Author], [Drawings].[Drawing Number], [Drawings].[Drawing Name], [Drawings].[Drawing Date], [Drawings].[Storage Location]
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    thaBadfish is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    6
    Damnit, why'd it have to be such a simple solution? Works great now.

    Much appreciated!

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Happy to help, and welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    thaBadfish is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    6
    So I got everything working, and added my last requirement - an Add New Drawing button - and now the search feature no longer works! The subform only shows one result. For the life of me, I cannot figure out why. Can anyone take a look at the linked file and take a look?

    https://onedrive.live.com/redir?resi...t=file%2caccdb

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    You gave the main form a record source and master child links keep the subform from displaying anything except records linked to the hidden record on the main form.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    thaBadfish is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    6
    I can remove both Link Master Fields and Link Child Fields, which momentarily restores all results, but clicking search just hides them all except for one. I'm not sure how to resolve.

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    I deleted those plus the record source of the main form.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    thaBadfish is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    6
    If I delete the record source of the main form [Drawing Search], then it asks for ID and still only shows one record.

    **SORRY**

    I stand corrected, I hadn't deleted all 3 fields, only the record source of main form. Once I went back and "re"deleted the master and child links all was back to normal.

    Can't thank you enough.

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    No problemo! Basically the main form is a container for your search functions and the subform, so it doesn't need (and shouldn't have) a record source.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Delete Entry from subform using button
    By jobatiikanawong1987 in forum Access
    Replies: 1
    Last Post: 08-08-2013, 11:37 AM
  2. Replies: 0
    Last Post: 02-17-2013, 11:17 PM
  3. create a button to open a form for data entry
    By dave john in forum Programming
    Replies: 3
    Last Post: 08-21-2012, 08:41 AM
  4. Replies: 12
    Last Post: 03-22-2012, 02:48 AM
  5. Find Button won't work if Data Entry = Yes
    By Heatshiver in forum Forms
    Replies: 3
    Last Post: 12-23-2011, 01:49 PM

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