我们有一份包含患者详细信息的文件。
我们想要实现的是具有VBA表单,用户可以使用患者姓名和查看字段搜索医院号和D.O.B. - 它可以工作但基于数字字段。
找到患者后,使用该表格将额外信息添加到该患者的特定列。
'Declaring variables
Dim id As Integer, i As Integer, j As Integer, flag As Boolean
'Code to retrieve data based on ID - to be changed to string ( patients name
)
Sub GetData()
If IsNumeric(UserForm1.TextBox1.Value) Then
flag = False
i = 0
id = UserForm1.TextBox1.Value
Do While Cells(i + 1, 1).Value <> ""
If Cells(i + 1, 1).Value = id Then
flag = True
For j = 2 To 3
UserForm1.Controls("TextBox" & j).Value = Cells(i + 1, j).Value
Next j
End If
i = i + 1
Loop
If flag = False Then
For j = 2 To 3
UserForm1.Controls("TextBox" & j).Value = ""
Next j
End If
'Else
' ClearForm
End If
End Sub
'Sub to Add extra fields on the selected patient
Sub EditAdd()
Dim emptyCol As Long
If UserForm1.TextBox1.Value <> "" Then
flag = False
i = 0
id = UserForm1.TextBox1.Value
'emptyCol = WorksheetFunction.CountA(Range("A:Z")) + 1
emptyCol = WorksheetFunction.CountA(Columns(1)) + 1
Do While Cells(i + 1, 1).Value <> ""
If Cells(i + 1, 1).Value = id Then
flag = True
For j = 2 To 3
Cells(i + 1, j).Value = UserForm1.Controls("TextBox" & j).Value
Next j
End If
i = i + 1
Loop
If flag = False Then
For j = 1 To 3
Cells(emptyCol, j).Value = UserForm1.Controls("TextBox" & j).Value
Next j
End If
End If
End Sub
这是表单的外观(Textbox1到Textbox10从顶部到机器人。 应添加数据的列名称如下所示: 缩写,日期,死亡日期,死亡原因,心脏事件发生日期,心脏事件类型,评论