如果您没有时间处理所有这些背景,那么只需查看下面插入的SQL中的连接即可。
背景
我有一个数据库,用于跟踪公司的员工技能数据(当前年度和未来5年的预测)。 我很清楚我以不太好的方式设置了基表,所以我完全期待得到关于它的评论/建议。因此,如果完全改进我的设置并从头开始是我的最佳选择,我对这个想法持开放态度。但目前,以下是我的情况。
设置
问题
我最初有一个问题,我无法更改表单中的任何值(基本上,它是只读的),但后来我将所有关系更改为一对一,并修复了问题。 但是,我很明智地将 Name 字段名称更改为 EmpName (因为我读 Name 不是一个好的字段名称),现在当我尝试保存新数据或编辑时,我收到错误:
错误:您无法添加/更改~b / c相关记录是必需的&更新/取消更新没有AddNew /编辑)
我确实浏览了所有SQL和VBA代码,并将 Name 更改为 EmpName ,因此所有表/查询似乎都在纠正关联。此外,该数据库分为前端/后端。自从做出上述所有更改后,我已更新前端链接。此外,我可以将记录直接添加到表中。所以问题必须是关系或代码。
代码
连接到基本表单的查询的SQL如下所示。
SELECT [Developement Scenario Formation].Department, [Developement Scenario Formation].Title,
[Developement Scenario Formation].EmpName, [Developement Scenario Formation].[2017],
[Product Design].[2017], [Technical Information Gathering].[2017],
[Developement and Design Commissions].[2017],
[Plant Support].[2017], [Quality Issues Management].[2017],
[Overall Product].[2017], [Product Knowledge].[2017], [Safety/Health/Env Knowledge].[2017],
[Equipment Maintenance].[2017], [Measuring Instruments].[2017],
[Report Making].[2017], [Reports and Information Acquisition].[2017], Language.[2017],
OA.[2017], [Developement Scenario Formation].Status,
[Developement Scenario Formation].[Inactive Date]
FROM [Report Making] INNER JOIN ([Quality Issues Management]
INNER JOIN ([Overall Product]
INNER JOIN (OA INNER JOIN (((((((((([Developement and Design Commissions]
INNER JOIN [Developement Scenario Formation]
ON [Developement and Design Commissions].EmpName = [Developement Scenario Formation].EmpName)
INNER JOIN [Equipment Maintenance]
ON [Developement Scenario Formation].EmpName = [Equipment Maintenance].EmpName)
INNER JOIN [Language] ON [Developement Scenario Formation].EmpName = Language.EmpName)
INNER JOIN [Measuring Instruments]
ON [Developement Scenario Formation].EmpName = [Measuring Instruments].EmpName)
INNER JOIN [Plant Support]
ON [Developement Scenario Formation].EmpName = [Plant Support].EmpName)
INNER JOIN [Product Design]
ON [Developement Scenario Formation].EmpName = [Product Design].EmpName)
INNER JOIN [Product Knowledge]
ON [Developement Scenario Formation].EmpName = [Product Knowledge].EmpName)
INNER JOIN [Reports and Information Acquisition]
ON [Developement Scenario Formation].EmpName = [Reports and Information Acquisition].EmpName)
INNER JOIN [Safety/Health/Env Knowledge]
ON [Developement Scenario Formation].EmpName = [Safety/Health/Env Knowledge].EmpName)
INNER JOIN [Technical Information Gathering]
ON [Developement Scenario Formation].EmpName = [Technical Information Gathering].EmpName)
ON OA.EmpName = [Developement Scenario Formation].EmpName)
ON [Overall Product].EmpName = [Developement Scenario Formation].EmpName)
ON [Quality Issues Management].EmpName = [Developement Scenario Formation].EmpName)
ON [Report Making].EmpName = [Developement Scenario Formation].EmpName;
我还为表单添加了VBA代码,因为这可能导致“On Update”错误。
Private Sub LEAVESUBFORMDUMMY_GotFocus()
Me.[cntrlDevelopement Scenario Formation.2018].SetFocus
Parent.SetFocus
Parent.[SbFrm_2018 LEVELS (ALL)].SetFocus
Parent.[SbFrm_2018 LEVELS (ALL)]![cntrlDevelopement Scenario Formation.2019].SetFocus
End Sub
Private Sub Form_Activate()
If Me.AllowAdditions Or Me.AllowEdits Or Me.AllowDeletions Then
Me.Command57.Visible = True
Else
Me.Command57.Visible = False
End If
End Sub
Private Sub Form_AfterDelConfirm(Status As Integer)
If Status = acDeleteOK Then Call AuditChanges("Action", "DELETE", Form)
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.NewRecord Then
Call AuditChanges("Action", "NEW", Form)
Else
Call AuditChanges("Action", "EDIT", Form)
End If
End Sub
Private Sub Form_Current()
If Me.AllowEdits Then
Me.Command73.Visible = True
Me.Toggle96.Visible = True
Else
Me.Command73.Visible = False
Me.Toggle96.Visible = False
End If
End Sub
Private Sub Form_Open(Cancel As Integer)
Me.Filter = "[Status] = 'Active'"
Me.FilterOn = True
Me.Requery
End Sub
Private Sub Form_Resize()
If Me.AllowAdditions Or Me.AllowEdits Or Me.AllowDeletions Then
Me.Label94.Visible = True
Else
Me.Label94.Visible = False
End If
End Sub
Private Sub Toggle96_AfterUpdate()
If Me.Toggle96 = True Then
Me.Filter = "[Status] = 'Inactive'"
Me.FilterOn = True
Else
Me.Filter = "[Status] = 'Active'"
Me.FilterOn = True
End If
End Sub
Private Sub Toggle96_Click()
If Me.AllowEdits = True Then
Me.AllowEdits = False
Me.SbFrm_2018_LEVELS__ALL_.Locked = True
Me.SbFrm2019_LEVELS__ALL_.Locked = True
Me.SbFrm2020_LEVELS__ALL_.Locked = True
Me.SbFrm2021_LEVELS__ALL_.Locked = True
Me.SbFrm2022_LEVELS__ALL_.Locked = True
Me.Command97.SetFocus
Me.Command73.Visible = False
Me.Command57.Visible = False
Me.Label94.Visible = False
Me.Toggle96.Visible = False
Else
Me.AllowEdits = True
Me.Command73.Visible = True
Me.Command57.Visible = True
Me.Label94.Visible = True
Me.Toggle96.Caption = "Show Inactive Profiles"
End If
End Sub
我知道,这太乱了。但基本上,我只需要能够添加新记录并更新现有记录。如果您有任何帮助,我将非常感激。谢谢。