什么可以导致焦点在Access 2010 / VBA中设置,而不是SetFocus?

时间:2013-09-25 15:17:00

标签: sql vba ms-access ms-access-2010 setfocus

我有一个连续的子表单,它根据字符串的值从两个查询之一中获取数据。

使用第一个查询,焦点设置在第一行的第一个文本框(Prospect_Name)上,如预期的那样。我没有使用SetFocus来设置焦点,这是它自动选择的。

对于第二行,焦点设置在第一行(ID)的另一个文本框上,这导致了我各种各样的问题 - 我没有打开水平滚动条,这个菜单意味着“ offscreeen“,但如果焦点设置为它,子窗体会自动滚动到该值。焦点始终设置为该文本框。它不是横向的,也不是那样的。

我已经检查过并且没有SetFocus将焦点移动到ID,所以为什么要这样做呢?我认为它必须与第二个查询有关,因为这是唯一改变的东西?第二个查询是联合查询,这可能是罪魁祸首吗?

下面的查询,虽然它们有点长,所以我不知道它们会有多大的帮助。

工作查询:

SELECT Prospects.ID, Prospects.Company, Prospects.[Registered No], Prospects.[Limited Company], Prospects.[Originally Known As], Prospects.Office AS [BF Office], Prospects.Partner, Prospects.Partner2, Prospects.Partner3, Prospects.Status, Prospects.[SIC Code], Prospects.TPSMPS, Prospects.Website, Prospects.Sector, Prospects.[Turnover Bracket], Prospects.Turnover, Prospects.[Turnover Min], Prospects.[Turnover Max], Prospects.Accountant, Prospects.Bank, Prospects.Solicitor, Prospects.Employees, Prospects.[Audit Fee], Prospects.CharityType, Prospects.Sourceoffinancials, Prospects.DateCreated, Prospects.Createby, Prospects.DateModified, Prospects.Modifiedby, Prospects.[Key Contact], Prospects.[Address Type], Prospects.Address1, Prospects.Address2, Prospects.Address3, Prospects.Town, Prospects.County, Prospects.Postcode, Prospects.[Telephone Number], Prospects.Email, Prospects.[Incorrect Emails], Prospects.Telemarket, Prospects.Sourceofdata, Prospects.Clientcode, Prospects.DateConverted, Prospects.[Number of Beds in Group], Prospects.[Number of Homes in Group], Prospects.[Healthcare Type], Prospects.CharitiesT, Prospects.WManagementT, Prospects.CareT, Prospects.PropertyT, Prospects.LeisureTourismT, Prospects.MarineT, Prospects.MediaCreativeT, Prospects.ProPracticesT, Prospects.MotorT, Prospects.PersonalTaxT, Prospects.TaxT, Prospects.VATT, Prospects.PayrollT, Prospects.AuditT, Prospects.SAGET, Prospects.AccountsT, Prospects.CFinT, Prospects.BusinessRecoveryT, Prospects.ForensicT, Prospects.GrantT, Prospects.IFAT, Prospects.IntTaxT, Prospects.TaxInvT, Prospects.RenewablesT, Prospects.AcademiesT, Prospects.MTIT, [Prospects]![NextContact] AS NextContactA, Nz([NextContact],"~") AS NextContactNZ, Nz([Key Contacts]![Last Name],"zz") AS KeyContact1NZ, Nz([Key Contacts]![First Name],"~") AS KeyContact2NZ, Nz([Most Recent Contact]![SortA],"zz") AS DateNZ, [Most Recent Contact.SortA] AS DateA, [Most Recent Contact].Information AS [Note Full Info], [Key Contacts].[First Name], Prospects.[Holding Company], Prospects.[TPS/CTPS], Prospects.[Top 500], Prospects.NextContact, Prospects.[Payroll Status], [Key Contacts].[Key Contact E-Mail], [Key Contacts].[Key Contact], [Most Recent Contact].*, [Date] & IIf([Date] Is Not Null,": ","") & [Title] AS [Note Information], "N/A" AS [Filter Checker], Prospects.Company AS [Group], "Parent" AS [Parent / Child], [Most Recent Contact].[Added by] AS [Note author], Nz(Right((Left([NextContactA],10)),4) & Mid([NextContactA],4,2) & Left([NextContactA],2),"zz") AS NextContactSortA
    FROM ((Prospects LEFT JOIN [Key Contacts] ON Prospects.ID = [Key Contacts].ID) LEFT JOIN [Most Recent Contact] ON Prospects.ID = [Most Recent Contact].[Prospect ID]) INNER JOIN [Report - Holding Filter] ON Prospects.ID = [Report - Holding Filter].ID
    WHERE (((Prospects.Status) Not Like "Duplicate") AND ((Prospects.Company) Like "*" & [Forms]![Reports]![Search Text] & "*"))
    ORDER BY Prospects.Company;

查询导致问题:

SELECT * FROM [SearchByName] UNION SELECT * FROM [SearchByName - GrandChildren];

该查询的第一部分(SearchByName)是上一个查询,第二部分如下:

SELECT * FROM [SearchByName - Holding Companies] UNION SELECT * FROM [SearchByName - Level 1 subsidiaries];

它本身由以下两个查询组成:

SELECT [SearchByName - No Filter].ID, [SearchByName - No Filter].Company, [SearchByName - No Filter].[Registered No], [SearchByName - No Filter].[Limited Company], [SearchByName - No Filter].[Originally Known As], [SearchByName - No Filter].[BF Office], [SearchByName - No Filter].Partner, [SearchByName - No Filter].Partner2, [SearchByName - No Filter].Partner3, [SearchByName - No Filter].Status, [SearchByName - No Filter].[SIC Code], [SearchByName - No Filter].TPSMPS, [SearchByName - No Filter].Website, [SearchByName - No Filter].Sector, [SearchByName - No Filter].[Turnover Bracket], [SearchByName - No Filter].Turnover, [SearchByName - No Filter].[Turnover Min], [SearchByName - No Filter].[Turnover Max], [SearchByName - No Filter].Accountant, [SearchByName - No Filter].Bank, [SearchByName - No Filter].Solicitor, [SearchByName - No Filter].Employees, [SearchByName - No Filter].[Audit Fee], [SearchByName - No Filter].CharityType, [SearchByName - No Filter].Sourceoffinancials, [SearchByName - No Filter].DateCreated, [SearchByName - No Filter].Createby, [SearchByName - No Filter].DateModified, [SearchByName - No Filter].Modifiedby, [SearchByName - No Filter].Prospects.[Key Contact], [SearchByName - No Filter].[Address Type], [SearchByName - No Filter].Address1, [SearchByName - No Filter].Address2, [SearchByName - No Filter].Address3, [SearchByName - No Filter].Town, [SearchByName - No Filter].County, [SearchByName - No Filter].Postcode, [SearchByName - No Filter].[Telephone Number], [SearchByName - No Filter].Email, [SearchByName - No Filter].[Incorrect Emails], [SearchByName - No Filter].Telemarket, [SearchByName - No Filter].Sourceofdata, [SearchByName - No Filter].Clientcode, [SearchByName - No Filter].DateConverted, [SearchByName - No Filter].[Number of Beds in Group], [SearchByName - No Filter].[Number of Homes in Group], [SearchByName - No Filter].[Healthcare Type], [SearchByName - No Filter].CharitiesT, [SearchByName - No Filter].WManagementT, [SearchByName - No Filter].CareT, [SearchByName - No Filter].PropertyT, [SearchByName - No Filter].LeisureTourismT, [SearchByName - No Filter].MarineT, [SearchByName - No Filter].MediaCreativeT, [SearchByName - No Filter].ProPracticesT, [SearchByName - No Filter].MotorT, [SearchByName - No Filter].PersonalTaxT, [SearchByName - No Filter].TaxT, [SearchByName - No Filter].VATT, [SearchByName - No Filter].PayrollT, [SearchByName - No Filter].AuditT, [SearchByName - No Filter].SAGET, [SearchByName - No Filter].AccountsT, [SearchByName - No Filter].CFinT, [SearchByName - No Filter].BusinessRecoveryT, [SearchByName - No Filter].ForensicT, [SearchByName - No Filter].GrantT, [SearchByName - No Filter].IFAT, [SearchByName - No Filter].IntTaxT, [SearchByName - No Filter].TaxInvT, [SearchByName - No Filter].RenewablesT, [SearchByName - No Filter].AcademiesT, [SearchByName - No Filter].MTIT, [SearchByName - No Filter].NextContactA, [SearchByName - No Filter].NextContactNZ, [SearchByName - No Filter].KeyContact1NZ, [SearchByName - No Filter].KeyContact2NZ, [SearchByName - No Filter].DateNZ, [SearchByName - No Filter].DateA, [SearchByName - No Filter].[Note Full Info], [SearchByName - No Filter].[First Name], [SearchByName - No Filter].[Holding Company], [SearchByName - No Filter].[TPS/CTPS], [SearchByName - No Filter].[Top 500], [SearchByName - No Filter].NextContact, [SearchByName - No Filter].[Payroll Status], [SearchByName - No Filter].[Key Contact E-Mail], [SearchByName - No Filter].[Key Contacts].[Key Contact], [SearchByName - No Filter].[Lead ID], [SearchByName - No Filter].Information, [SearchByName - No Filter].[Prospect ID], [SearchByName - No Filter].Title, [SearchByName - No Filter].Date, [SearchByName - No Filter].Hyperlink, [SearchByName - No Filter].[Added by], [SearchByName - No Filter].SortA, [SearchByName - No Filter].[Note Information], [SearchByName - No Filter].[Filter Checker], [SearchByName - No Filter].Group, "Parent" AS [Parent / Child], [SearchByName - No Filter].[Added by] AS [Note Author], " " AS [Intentionally blank]
FROM [SearchByName - No Filter] INNER JOIN [SearchByName - Level 1 Subsidiaries] ON [SearchByName - No Filter].ID = [SearchByName - Level 1 Subsidiaries].[Holding Company];

SELECT [SearchByName - No filter].ID, "     " & [Subsidiaries]![Company] & " (subsidiary of " & [SearchByName - No Filter]![Company] & ")" AS Company, Subsidiaries.[Registered No], [SearchByName - No filter].[Limited Company], [SearchByName - No filter].[Originally Known As], [SearchByName - No filter].[BF Office], [SearchByName - No filter].Partner, [SearchByName - No filter].Partner2, [SearchByName - No filter].Partner3, [SearchByName - No filter].Status, [SearchByName - No filter].[SIC Code], [SearchByName - No filter].TPSMPS, [SearchByName - No filter].Website, [SearchByName - No filter].Sector, [SearchByName - No filter].[Turnover Bracket], [SearchByName - No filter].Turnover, [SearchByName - No filter].[Turnover Min], [SearchByName - No filter].[Turnover Max], [SearchByName - No filter].Accountant, [SearchByName - No filter].Bank, [SearchByName - No filter].Solicitor, [SearchByName - No filter].Employees, [SearchByName - No filter].[Audit Fee], [SearchByName - No filter].CharityType, [SearchByName - No filter].Sourceoffinancials, [SearchByName - No filter].DateCreated, [SearchByName - No filter].Createby, [SearchByName - No filter].DateModified, [SearchByName - No filter].Modifiedby, [SearchByName - No filter].Prospects.[Key Contact], [SearchByName - No filter].[Address Type], [SearchByName - No filter].Address1, [SearchByName - No filter].Address2, [SearchByName - No filter].Address3, [SearchByName - No filter].Town, [SearchByName - No filter].County, [SearchByName - No filter].Postcode, [SearchByName - No filter].[Telephone Number], [SearchByName - No filter].Email, [SearchByName - No filter].[Incorrect Emails], [SearchByName - No filter].Telemarket, [SearchByName - No filter].Sourceofdata, [SearchByName - No filter].Clientcode, [SearchByName - No filter].DateConverted, [SearchByName - No filter].[Number of Beds in Group], [SearchByName - No filter].[Number of Homes in Group], [SearchByName - No filter].[Healthcare Type], [SearchByName - No filter].CharitiesT, [SearchByName - No filter].WManagementT, [SearchByName - No filter].CareT, [SearchByName - No filter].PropertyT, [SearchByName - No filter].LeisureTourismT, [SearchByName - No filter].MarineT, [SearchByName - No filter].MediaCreativeT, [SearchByName - No filter].ProPracticesT, [SearchByName - No filter].MotorT, [SearchByName - No filter].PersonalTaxT, [SearchByName - No filter].TaxT, [SearchByName - No filter].VATT, [SearchByName - No filter].PayrollT, [SearchByName - No filter].AuditT, [SearchByName - No filter].SAGET, [SearchByName - No filter].AccountsT, [SearchByName - No filter].CFinT, [SearchByName - No filter].BusinessRecoveryT, [SearchByName - No filter].ForensicT, [SearchByName - No filter].GrantT, [SearchByName - No filter].IFAT, [SearchByName - No filter].IntTaxT, [SearchByName - No filter].TaxInvT, [SearchByName - No filter].RenewablesT, [SearchByName - No filter].AcademiesT, [SearchByName - No filter].MTIT, [SearchByName - No filter].NextContactA, [SearchByName - No filter].NextContactNZ, [SearchByName - No filter].KeyContact1NZ, [SearchByName - No filter].KeyContact2NZ, [SearchByName - No filter].DateNZ, [SearchByName - No filter].DateA, [SearchByName - No filter].[Note Full Info], [SearchByName - No filter].[First Name], Subsidiaries.[Holding Company], [SearchByName - No filter].[TPS/CTPS], [SearchByName - No filter].[Top 500], [SearchByName - No filter].NextContact, [SearchByName - No filter].[Payroll Status], [SearchByName - No filter].[Key Contact E-Mail], [SearchByName - No filter].[Key Contacts].[Key Contact], [SearchByName - No filter].[Lead ID], [SearchByName - No filter].Information, [SearchByName - No filter].[Prospect ID], [SearchByName - No filter].Title, [SearchByName - No filter].Date, [SearchByName - No filter].Hyperlink, [SearchByName - No filter].[Added by], [SearchByName - No filter].SortA, [SearchByName - No filter].[Note Information], [SearchByName - No filter].[Filter Checker], [SearchByName - No filter].Group, "Child" AS [Parent / Child], [SearchByName - No filter].[Added by] AS [Note Author], " " AS [Intentionally blank]
FROM Prospects AS Subsidiaries INNER JOIN [SearchByName - No filter] ON Subsidiaries.[Holding Company] = [SearchByName - No filter].ID
WHERE ((("     " & [Subsidiaries]![Company] & " (subsidiary of " & [SearchByName - No Filter]![Company] & ")") Like "*" & [Forms]![Reports]![Search Text] & "*"));

1 个答案:

答案 0 :(得分:1)

由于问题是由于Access设置焦点在您不想要显示的文本框上,因此通过将其Visible属性设置为No来隐藏该文本框。 Access无法将焦点设置为隐藏字段。