Hi,
Disclaimer: I am an MS Access rookie. I just learned it this week.
I’ve been tasked to create a database for my job, and I have everything set up, but I can’t get the search qualifications to work (or whatever they are called, which I guess depends on which way you set them up). Basically, what I need is for a user to be able to input data on a form, and filter/search a database based off of that data. I’ll try and explain in detail.
I’m using Access 2007, and what I need to do is set it up so the user can put information on a form, hit a search button, and filter the database. For example, you put information in 3 of 12 fields, and then when you click the search command, the query only shows the records that have the entered information in each of the 3 fields. Obviously, the information entered is different for each of the fields.
Now I’ve tried one method, from Microsoft’s website, that seems like it should work, but it doesn’t. Here is a link to the article I followed, https://support.microsoft.com/en-us/...n-us/kb/304428. This was for Access 2003, but I figured it would work for me.
I set everything up like the article says:
I imported the database (table) from Excel, I called it STIG Database.
I created a Form (called it Search) with the fields (that correspond with the columns in the STIG Database), and set up the Command Button for OnClick ‘SearchMacro’ (The name of my macro).
Created a Macro ‘SearchMacro’ to look like this Action-OpenQuery;Argument-STIG Query, Datasheet, Read Only.
Created a Query ‘STIG Query’ with all of the columns of the database (table/workbook) as the Fields. For simplicity sake I’ll just use two of the fields. Vuln ID and 800-53
Now for the ‘Vuln ID’ field I put the criteria in like this:
[Forms]![Search]![Vuln ID] Or [Forms]![Search]![Vuln ID] Is Null
And for the ‘800-53’ field I put:
[Forms]![Search]![800-53] Or [Forms]![Search]![800-53] Is Null
I kept the names of the fields on the Form the same as the Column Headings in the STIG Database.
This is the SQL view of the information:
SELECT [STIG Database].[Vuln ID], [STIG Database].[STIG ID], [STIG Database].[IA Controls], [STIG Database].Mitigations, [STIG Database].Responsibility, [STIG Database].Classification, [STIG Database].STIG, [STIG Database].[VMS Asset Posture], [STIG Database].CCI, [STIG Database].[800-53], [STIG Database].[800-53A], [STIG Database].[800-53 Rev 4]
FROM [STIG Database]
WHERE ((([STIG Database].[Vuln ID])=[Forms]![Search]![Vuln ID] Or [Forms]![Search]![Vuln Id] Is Null) AND (([STIG Database].[800-53])=[Forms]![Search]![800-53] Or [Forms]![Search]![800-53] Is Null));
No matter what information I put in it always shows me the entire database and doesn’t filter anything.
I’ve changed some of the criteria around, such as remove the second (Null) part. I used simpler names for my names of Forms, Macros, Querys. I couldn’t get this to work. And I couldn’t get the test for Northwind database that they give you to work either, but I’m sure that’s because the fields didn’t line up since the instructions are for an older Access.
I looked at SQL stuff for this, but couldn’t find anything. I found something for VBA, but that is above my head. This is what I found, https://msdn.microsoft.com/en-us/lib...ffice.12).aspx
And this is the VBA code, buildcriteria method, it says to use
Sub SetFilter()
Dim frm As Form, strMsg As String
Dim strInput As String, strFilter As String
' Open Products form in Form view.
DoCmd.OpenForm "Products"
' Return Form object variable pointing to Products form.
Set frm = Forms!Products
strMsg = "Enter one or more letters of product name " _
& "followed by an asterisk."
' Prompt user for input.
strInput = InputBox(strMsg)
' Build criteria string.
strFilter = BuildCriteria("ProductName", dbText, strInput)
' Set Filter property to apply filter.
frm.Filter = strFilter
' Set FilterOn property; form now shows filtered records.
frm.FilterOn = True
End Sub
I couldn’t figure out what I needed to change, and how to apply it to the form.
If anyone could give me some guidance on how to do this it would be greatly appreciated.
Thanks in advance.