Access 2007创建新记录不会更新表单

时间:2015-01-22 16:56:58

标签: vba ms-access

我正在建立一个包含患者信息的数据库。现在,用户可以使用搜索/确认表单导航到特定患者信息(患者主页)。主页包含其他表格的链接以及其他患者信息。当用户搜索从一开始就被放入的患者时,代码就起作用(也就是我在开始时作为测试人员放入的“患者”将出现并且代码表现得如此)。但是,当我尝试添加新患者时,确认表将不再有效。新记录在患者列表中创建,搜索表单将找到新患者,但当我单击确认表上的继续按钮时,患者主页将作为新的(空白)记录拉出。该代码仅与新患者打破。

当我将新病人添加到主页表单时,我在“设备日志”表单中创建新记录时遇到问题。我在设备日志和患者主页之间存在一对一的关系,其中pt ID是两个表的主键。当我通过“pt主页”添加新患者时,我需要在设备日志中创建一个通过pt ID连接的链接记录。到目前为止,我已经尝试过类似下面的代码和其他类似的东西,但似乎没有任何效果。

搜索和确认页面的代码如下,以及患者主页的部分代码(虽然我不知道该代码非常有用)。感谢任何帮助,我已经坚持了一段时间。

患者检索页面:

Private Sub Patient_Search_Click()
On Error GoTo Patient_Search_Click_Err

DoCmd.OpenForm "Confirmation", acNormal, "", "", acReadOnly, acNormal


Patient_Search_Click_Exit:
Exit Sub

Patient_Search_Click_Err:
MsgBox Error$
Resume Patient_Search_Click_Exit

End Sub

Private Sub add_new_Click()
On Error GoTo add_new_Click_Err

' _AXL:<?xml version="1.0" encoding="UTF-16" standalone="no"?>
' <UserInterfaceMacro For="Patient Search" Event="OnClick"   xmlns="http://schemas.microsoft.com/office/accessservices/2009/11/application" xmlns:a="http://schemas.microsoft.com/office/accessserv
' _AXL:ices/2009/11/forms"><Statements><Action Name="OpenForm"><Argument Name="FormName">Confirmation</Argument><Argument Name="DataMode">Read Only</Argument></Action></Statements></UserInterfaceMacro>
DoCmd.OpenForm "Patient Home Page"
DoCmd.GoToRecord , , acNewRec

add_new_Click_Exit:
Exit Sub

add_new_Click_Err:
MsgBox Error$
Resume add_new_Click_Exit

End Sub

患者确认页面(*注意:我编辑了这个并在debug.print上添加了一个断点。当我运行命令时没有打印,现在什么都不会打开)

Private Sub confirm_Click() 
testid = [Patient List_ID]
Debug.Print 
DoCmd.OpenForm "Patient Home Page", acNormal, "", "[ID]=" & "'" & [Patient List_ID] & "'" 
End Sub

患者主页:

Private Sub Form_Current()
If Me.NewRecord Then
Me.equipment_log.Visible = False
Me.echos.Visible = False
Me.open_logs.Visible = False
Me.openadvisory.Visible = False
Me.save.Visible = True
Me.edit.Visible = False
Me.cancelupdate.Visible = True
Last_Name.Locked = False
First_Name.Locked = False
Middle_name.Locked = False
Device.Locked = False
Patient_List_ID.Locked = False
MRN.Locked = False
DOB.Locked = False
Implant_Date.Locked = False
Transplant_Goal.Locked = False
Status.Locked = False
Caregiver.Locked = False
Address.Locked = False
City.Locked = False
State.Locked = False
Zipcode.Locked = False
Phone_1.Locked = False
Phone_2.Locked = False
Phone_3.Locked = False
Else
Me.equipment_log.Visible = True
Me.echos.Visible = True
Me.open_logs.Visible = True
Me.openadvisory.Visible = True
Me.save.Visible = False
Me.edit.Visible = True
Me.cancelupdate.Visible = False
Last_Name.Locked = True
First_Name.Locked = True
Middle_name.Locked = True
Device.Locked = True
Patient_List_ID.Locked = True
MRN.Locked = True
DOB.Locked = True
Implant_Date.Locked = True
Transplant_Goal.Locked = True
Status.Locked = True
Caregiver.Locked = True
Address.Locked = True
City.Locked = True
State.Locked = True
Zipcode.Locked = True
Phone_1.Locked = True
Phone_2.Locked = True
Phone_3.Locked = True
End If
End Sub

在患者列表中的新条目(创建新记录的if语句内)中创建设备日志中的新记录

Dim crit As String
crit = [Patient List_ID]
DoCmd.OpenForm "Patient Equipment Log"
DoCmd.GoToRecord , , acNewRec
Forms![Patient Equipment Log]![Patient Equipment.ID] = crit

2 个答案:

答案 0 :(得分:1)

从您的声音中,您尝试打开表单查看之前,您的新患者并未被保存。因此,基本上你创建一个新患者并告诉第二种形式,以便在他们实际存在之前查看该患者&#34;在数据库的眼中。

Private Sub Patient_Search_Click()
On Error GoTo Patient_Search_Click_Err

    DoCmd.Save
    DoCmd.OpenForm "Confirmation", acNormal, "", "", acReadOnly, acNormal


Patient_Search_Click_Exit:
    Exit Sub

Patient_Search_Click_Err:
    MsgBox Error$
    Resume Patient_Search_Click_Exit

End Sub

答案 1 :(得分:1)

我终于明白了......显然我在某个地方拥有MRN相关的设备和患者名单。我在患者主页上的“保存”命令下添加了一个if语句,以检查患者设备列表中是否存在具有相同MRN的记录。如果没有,我创建了一个新记录。

Private Sub save_Click()
DoCmd.save
Dim crit As String
crit = [Patient List_ID]
DoCmd.OpenTable "Patient Equipment"
qcrit = DLookup("[ID]", "Patient Equipment", "[Patient List_ID]=" & "'" & crit & "'")
If StrComp(crit, qcrit) = 0 Then
    DoCmd.Close
Else
    DoCmd.OpenForm "Patient Equipment Log"
    DoCmd.GoToRecord , , acNewRec
    Forms![Patient Equipment Log]![MRN] = Forms![Patient Home Page]![MRN]
    Forms![Patient Equipment Log]![Patient Equipment.ID] = Forms![Patient Home Page]![Patient List_ID]
    Forms![Patient Equipment Log]![Implant Date] = Forms![Patient Home Page]![Implant Date]
    DoCmd.Close
End If