简体   繁体   中英

Access Search Subform + Update Query Subform?

So I'm new to Access 365, and I'm working on a database for my church's cemetery. I have a "main" form that will house searches and the results of said searches ( https://i.imgur.com/v6ZmDx2.png ).

So I'd like to put a box on this form that when I press the "Run Query" button, updates with all records matching the criteria. I have the query working, and if I go into the individual search form and search, it works fine.

If I try dragging the query onto the main form, I get a SearchQuery subform, but when I go into form view, I have to fill out data before the form even loads. I need it to only update after I click the button, so that I can enter info, THEN search ( https://i.imgur.com/6jJ416o.png & https://i.imgur.com/XPPpg6S.png ). If I click cancel, it loads fine, but when I type in data to the search then press "Run Query", it still prompts me for the info ( https://i.imgur.com/FKbZ6WK.png ).

Thanks in advance!

Your code is constructing criteria with control names as the data to search in, must use table field names. Remove the Result_ from each expression.

Coffin and Cremation radio buttons are within an OptionGroup control. This means you must test for the value of the OptionGroup, not the controls within the group. Clicking radio button sets value of the OptionGroup control. Following is revised code for the OptionGroup and checkboxes. Note removal of Result_ - fix the other conditional expressions as well. Might want to rename the OptionGroup control.

'Coffin/Cremation
If Not IsNull(Me.optGroup) Then strFilter = strFilter & "([Coffin/Cremation] = " & Me.optGroup & ") AND "

'Veteran
If Not IsNull(Me.Veteran) Then strFilter = strFilter & "([Veteran] = " & Me.Veteran & ") AND "

'Monument
If Not IsNull(Me.Monument) Then strFilter = strFilter & "([Monument] = " & Me.Monument & ") AND "

Why is the Clear Search button using EmbeddedMacro? Code to clear search parameters:

Private Sub cmdReset_Click()
    'Purpose:   Clear all the search boxes in the Form Header, and show all records again.
    Dim ctl As Control

    'Clear all the controls in the Form Header section.
    For Each ctl In Me.Section(acHeader).Controls
        Select Case ctl.ControlType
        Case acTextBox, acComboBox, acCheckBox, acOptionGroup
            ctl.Value = Null
        End Select
    Next

    'Remove the form's filter.
    Me.FilterOn = False
End Sub

Consider using comboboxes instead of textboxes to help users enter valid data. Can still allow any input and use LIKE/wildcard. RowSource SQL could be like:
SELECT DISTINCT [Last Name] FROM A ORDER BY [Last Name];

Advise not to use space nor punctuation/special characters (only exception is underscore) in naming convention.

You can access any form from the subform as follows: MainForm: LOAN SETTLEMENT FORM

ex:

Forms![LOAN SETTLEMENT FORM]!txtEMP_ID.Value = Me.EMP_ID.Value

Forms![LOAN SETTLEMENT FORM]!txtEMP_NAME.Value = Me.EMP_NAME.Value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM