从文本框值 Microsoft Access 2007 查看组合框值
Viewing combobox values from textbox values Microsoft Access 2007
我有一个表单 ("Patient Complications"),用户可以在其中使用 2 个级联组合框("catcombo" 和 "speccombo")将数据输入表单。组合框从 table ("Complications") 中提取它们的值。 table 有一个并发症类别字段(例如,感染、出血、机械)。第二个字段列出了特定的并发症(例如,如果并发症类别是 "bleeding",则特定的并发症可能是 "GI" 或 "other")。来自组合框的输入被连接起来并放入表单的文本字段中 ("Complication")。那部分工作正常。
我的表单有几个命令按钮,包括 "edit" 和 "save" 命令按钮。由于我不希望用户与表单上的 "complication" 字段进行交互,因此当单击 "edit" 按钮时该字段变得不可见。相反,2 个组合框变得可见并允许用户输入数据。 When "save" is selected, the reverse occurs.两个组合框变得不可见,并发症字段变得可见并被锁定。
Unfortunately, when "edit" is selected, the combo boxes are visible but show up blank (nothing is selected or displayed).我试图让方框显示提供给文本字段的输入。例如,如果文本字段显示 "Bleeding, Other",我希望 catcombo 框显示 "Bleeding",speccombo 框显示 "Other"。我一直无法找到任何与此相关的内容。如果有人有任何想法,将不胜感激。
相关代码如下。如果我可以提供进一步的说明,请告诉我。
Private Sub catcombo_AfterUpdate()
Me.speccombo.Requery
End Sub
Private Sub speccombo_OnCurrent()
Dim strsql As String
strsql = "SELECT [Complications]![Specific Complication] FROM tblComplications" & _
"WHERE [Complication Category]=Forms![Patient Complications]![catcombo].value"
End Sub
Private Sub speccombo_AfterUpdate()
Forms![Patient Complications]![Complication] = Me.catcombo.Value & ", " & Me.speccombo.Value
End Sub
Private Sub save_Click()
Me.recordcount.Caption = "Record " & Me.CurrentRecord & " of " & Me.Recordset.recordcount
Me.Patient_Initials.Visible = False
Date_of_Complication.Locked = True
Complication.Visible = True
Complication.Locked = True
comments.Locked = True
catcombo.Visible = False
speccombo.Visible = False
Me.edit.Visible = True
Me.edit.SetFocus
Me.help.Visible = False
Me.save.Visible = False
Me.first.Visible = True
Me.next.Visible = True
Me.previous.Visible = True
Me.last.Visible = True
Me.addnew.Visible = True
Me.close.Visible = True
Me.cancel.Visible = False
End Sub
Private Sub edit_Click()
Me.recordcount.Caption = "Record " & Me.CurrentRecord & " of " & Me.Recordset.recordcount
Me.Patient_Initials.Visible = False
Date_of_Complication.Locked = False
Complication.Visible = False
comments.Locked = False
catcombo.Visible = True
catcombo.Locked = False
catcombo.Enabled = True
speccombo.Visible = True
speccombo.Locked = False
speccombo.Enabled = True
Me.cancel.Visible = True
Me.cancel.SetFocus
Me.edit.Visible = False
Me.help.Visible = True
Me.save.Visible = True
Me.first.Visible = False
Me.next.Visible = False
Me.previous.Visible = False
Me.last.Visible = False
Me.addnew.Visible = False
Me.close.Visible = False
End Sub
我明白了。我在 "Complications" table 中添加了一个名为 "Input" 的字段。此字段包含已放入患者记录中的串联值(在上面的示例中,输入字段为 "Bleeding, Other")。输入字段中的值是将记录在患者并发症表 "Complication" 字段中的确切值。我将下面的 vba 代码添加到 "Edit" 命令按钮代码中。
If Not IsNull(Forms![Patient Complications]![Complication]) Then
Dim comptext As String
Dim spectext As String
comptext = DLookup("[Complication Category]", "Complications", "Input = Forms![Patient Complications]![Complication]")
catcombo.Value = comptext
spectext = DLookup("[Specific Complication]", "Complications", "Input=Forms![Patient Complications]![Complication]")
speccombo.Value = spectext
End If
这解决了我最初的问题,但随后我遇到了一个问题,即 speccombo 框显示的是最后一个给定的值。例如,如果 speccombo.value="GI" 当我点击 "edit" 时,它将继续显示 "GI" 直到再次选择。这没什么大不了的,只是不方便。如果更改了 catcombo,我想让 speccombo 框基本上归零。我添加了下面的代码来解决这个问题。
Private Sub catcombo_AfterUpdate()
Me.speccombo.Requery
Me.speccombo.Value = Null
End Sub
如果我需要澄清任何事情,请告诉我。
我有一个表单 ("Patient Complications"),用户可以在其中使用 2 个级联组合框("catcombo" 和 "speccombo")将数据输入表单。组合框从 table ("Complications") 中提取它们的值。 table 有一个并发症类别字段(例如,感染、出血、机械)。第二个字段列出了特定的并发症(例如,如果并发症类别是 "bleeding",则特定的并发症可能是 "GI" 或 "other")。来自组合框的输入被连接起来并放入表单的文本字段中 ("Complication")。那部分工作正常。
我的表单有几个命令按钮,包括 "edit" 和 "save" 命令按钮。由于我不希望用户与表单上的 "complication" 字段进行交互,因此当单击 "edit" 按钮时该字段变得不可见。相反,2 个组合框变得可见并允许用户输入数据。 When "save" is selected, the reverse occurs.两个组合框变得不可见,并发症字段变得可见并被锁定。
Unfortunately, when "edit" is selected, the combo boxes are visible but show up blank (nothing is selected or displayed).我试图让方框显示提供给文本字段的输入。例如,如果文本字段显示 "Bleeding, Other",我希望 catcombo 框显示 "Bleeding",speccombo 框显示 "Other"。我一直无法找到任何与此相关的内容。如果有人有任何想法,将不胜感激。
相关代码如下。如果我可以提供进一步的说明,请告诉我。
Private Sub catcombo_AfterUpdate()
Me.speccombo.Requery
End Sub
Private Sub speccombo_OnCurrent()
Dim strsql As String
strsql = "SELECT [Complications]![Specific Complication] FROM tblComplications" & _
"WHERE [Complication Category]=Forms![Patient Complications]![catcombo].value"
End Sub
Private Sub speccombo_AfterUpdate()
Forms![Patient Complications]![Complication] = Me.catcombo.Value & ", " & Me.speccombo.Value
End Sub
Private Sub save_Click()
Me.recordcount.Caption = "Record " & Me.CurrentRecord & " of " & Me.Recordset.recordcount
Me.Patient_Initials.Visible = False
Date_of_Complication.Locked = True
Complication.Visible = True
Complication.Locked = True
comments.Locked = True
catcombo.Visible = False
speccombo.Visible = False
Me.edit.Visible = True
Me.edit.SetFocus
Me.help.Visible = False
Me.save.Visible = False
Me.first.Visible = True
Me.next.Visible = True
Me.previous.Visible = True
Me.last.Visible = True
Me.addnew.Visible = True
Me.close.Visible = True
Me.cancel.Visible = False
End Sub
Private Sub edit_Click()
Me.recordcount.Caption = "Record " & Me.CurrentRecord & " of " & Me.Recordset.recordcount
Me.Patient_Initials.Visible = False
Date_of_Complication.Locked = False
Complication.Visible = False
comments.Locked = False
catcombo.Visible = True
catcombo.Locked = False
catcombo.Enabled = True
speccombo.Visible = True
speccombo.Locked = False
speccombo.Enabled = True
Me.cancel.Visible = True
Me.cancel.SetFocus
Me.edit.Visible = False
Me.help.Visible = True
Me.save.Visible = True
Me.first.Visible = False
Me.next.Visible = False
Me.previous.Visible = False
Me.last.Visible = False
Me.addnew.Visible = False
Me.close.Visible = False
End Sub
我明白了。我在 "Complications" table 中添加了一个名为 "Input" 的字段。此字段包含已放入患者记录中的串联值(在上面的示例中,输入字段为 "Bleeding, Other")。输入字段中的值是将记录在患者并发症表 "Complication" 字段中的确切值。我将下面的 vba 代码添加到 "Edit" 命令按钮代码中。
If Not IsNull(Forms![Patient Complications]![Complication]) Then
Dim comptext As String
Dim spectext As String
comptext = DLookup("[Complication Category]", "Complications", "Input = Forms![Patient Complications]![Complication]")
catcombo.Value = comptext
spectext = DLookup("[Specific Complication]", "Complications", "Input=Forms![Patient Complications]![Complication]")
speccombo.Value = spectext
End If
这解决了我最初的问题,但随后我遇到了一个问题,即 speccombo 框显示的是最后一个给定的值。例如,如果 speccombo.value="GI" 当我点击 "edit" 时,它将继续显示 "GI" 直到再次选择。这没什么大不了的,只是不方便。如果更改了 catcombo,我想让 speccombo 框基本上归零。我添加了下面的代码来解决这个问题。
Private Sub catcombo_AfterUpdate()
Me.speccombo.Requery
Me.speccombo.Value = Null
End Sub
如果我需要澄清任何事情,请告诉我。