我在访问中有一个用于存储/编辑数据的表单。其中一个功能是搜索功能。我在其相关字段中键入任何数据并点击搜索按钮,它会提取与描述匹配的任何记录。我有5种不同的组合框用于推荐不同的培训课程。现在,如果我想查找1个课程,我将不得不在每个组合框中选择该课程,因为它可能在5中的任何一个。我想知道是否有一种方法可以重写它所以我可以将课程改为5中的一个,它仍将搜索所有5个字段的数据?搜索查询代码如下:
SELECT CDData.EmployeeID, CDData.EmployeeName, CDData.Gender, CDData.EEOC,
CDData.ReadinessLevel, CDData.Division, CDData.Center, CDData.EmployeeFeedback,
CDData.DevelopmentForEmployee1, CDData.DevelopmentForEmployee2,
CDData.DevelopmentForEmployee3, CDData.DevelopmentForEmployee4,
CDData.DevelopmentForEmployee5, CDData.Justification, CDData.Changed
FROM CDData
WHERE
(((CDData.EmployeeID) Like "*" & [Forms]![frmCDData]![txtEmpID] & "*") AND
((CDData.EmployeeName) Like "*" & [Forms]![frmCDData]![txtEmpName] & "*") AND
((CDData.Gender) Like "*" & [Forms]![frmCDData]![cboGender] & "*") AND
((CDData.EEOC) Like "*" & [Forms]![frmCDData]![cboEEOC] & "*") AND
((CDData.ReadinessLevel) Like "*" & [Forms]![frmCDData]![cboReadyLvl] & "*") AND
((CDData.Division) Like "*" & [Forms]![frmCDData]![cboDivision] & "*") AND
((CDData.Center) Like "*" & [Forms]![frmCDData]![txtCenter] & "*") AND
((CDData.EmployeeFeedback) Like "*" & [Forms]![frmCDData]![txtFeedback] & "*") AND
((CDData.DevelopmentForEmployee1) Like "*" & [Forms]![frmCDData]![cboDevelopment1] & "*") AND
((CDData.DevelopmentForEmployee2) Like "*" & [Forms]![frmCDData]![cboDevelopment2] & "*") AND
((CDData.DevelopmentForEmployee3) Like "*" & [Forms]![frmCDData]![cboDevelopment3] & "*") AND
((CDData.DevelopmentForEmployee4) Like "*" & [Forms]![frmCDData]![cboDevelopment4] & "*") AND
((CDData.DevelopmentForEmployee5) Like "*" & [Forms]![frmCDData]![cboDevelopment5] & "*") AND
((CDData.Justification) Like "*" & [Forms]![frmCDData]![txtJustification] & "*") AND ((CDData.Changed) Like "*" & [Forms]![frmCDData]![cboChanged] & "*"));
答案 0 :(得分:0)
我想你想稍微规范化这些数据。我会在其中有一个单独的表,其中包含EmployeeID和DevelopmentForEmployee,并将其链接回主表。通过这种方式,您可以在此新表中搜索DevelopmentForEmployee以及仅查询到EmployeeID上的主表的INNER JOIN。然后,它最终应该看起来像:
SELECT CDData.EmployeeID, CDData.EmployeeName, CDData.Gender, CDData.EEOC,
CDData.ReadinessLevel, CDData.Division, CDData.Center, CDData.EmployeeFeedback,
CDData.DevelopmentForEmployee1, CDData.DevelopmentForEmployee2,
CDData.DevelopmentForEmployee3, CDData.DevelopmentForEmployee4,
CDData.DevelopmentForEmployee5, CDData.Justification, CDData.Changed
FROM CDData
INNER JOIN (SELECT * FROM MyNewTable WHERE DevelopmentForEmployee Like "*" & [Forms]![frmCDData]![cboDevelopment1] & "*")
as DevForEmp
ON CDATA.EmployeeID = DevForEmp .EmployeeID
WHERE
(((CDData.EmployeeID) Like "*" & [Forms]![frmCDData]![txtEmpID] & "*") AND
((CDData.EmployeeName) Like "*" & [Forms]![frmCDData]![txtEmpName] & "*") AND
((CDData.Gender) Like "*" & [Forms]![frmCDData]![cboGender] & "*") AND
((CDData.EEOC) Like "*" & [Forms]![frmCDData]![cboEEOC] & "*") AND
((CDData.ReadinessLevel) Like "*" & [Forms]![frmCDData]![cboReadyLvl] & "*") AND
((CDData.Division) Like "*" & [Forms]![frmCDData]![cboDivision] & "*") AND
((CDData.Center) Like "*" & [Forms]![frmCDData]![txtCenter] & "*") AND
((CDData.EmployeeFeedback) Like "*" & [Forms]![frmCDData]![txtFeedback] & "*") AND
((CDData.Justification) Like "*" & [Forms]![frmCDData]![txtJustification] & "*") AND
((CDData.Changed) Like "*" & [Forms]![frmCDData]![cboChanged] & "*"));
可能需要一些调整,但这可能非常接近。