ms access vba显示表单中复合键的所有字段
我正在寻找一种方法来显示表单字段中复合键涉及的所有字段。这是为了帮助用户在输入多个记录时跟踪他们正在处理的记录。目前,Access 将仅显示在复合键的字段上。
在表单上,我当前有一个查找字段链接到 HeaderData 表。我想从中获取值并在表单字段中查找并显示关联的记录,以便用户知道他们已经输入了正确的输入,并且在数据输入过程中不会丢失其位置。
这是我尝试过的,但没有显示任何结果:
Private Sub ProviderName_LostFocus()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim vcatch As String
strSQL = "SELECT ID, AgencyID, ProviderName, AssessmentPeriod FROM HeaderData"
Set db = CurrentDb
Set rs = db.OpenRecordset("strSQL", dbOpenDynaset)
If Not (rs.BOF And rs.EOF) Then
rs.MoveFirst
Do While Not rs.EOF
If Me.ProviderName.Value = rs.Fields(ProviderName) Then
vcatch = rs.Fields(ID) + " " + rs.Fields(AgencyID) + " " + rs.Fields(ProviderName) + " " + rs.Fields(AssessmentPeriod)
Me.Text22 = vcatch
rs.MoveLast
Else
rs.MoveNext
End If
Loop
Me.Tally1.SetFocus
End If
rs.Close
db.Close
End Sub
我查看了所有内容,但找不到有关显示所有字段的任何内容。任何帮助将不胜感激。
I am looking for a way to display all fields involved in a composite key in a form field. This is to aid the users when they are entering multiple records to keep track of which they are working on. Currently, Access will only display on field from the Composite key.
On the form, I currently have a look up field to link to the HeaderData table. I want to take the value from that and find and display the associated record in a form field so users will know that they have entered the correct input and do not lose their place during data entry.
Here is what I tried, but I am showing no results:
Private Sub ProviderName_LostFocus()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim vcatch As String
strSQL = "SELECT ID, AgencyID, ProviderName, AssessmentPeriod FROM HeaderData"
Set db = CurrentDb
Set rs = db.OpenRecordset("strSQL", dbOpenDynaset)
If Not (rs.BOF And rs.EOF) Then
rs.MoveFirst
Do While Not rs.EOF
If Me.ProviderName.Value = rs.Fields(ProviderName) Then
vcatch = rs.Fields(ID) + " " + rs.Fields(AgencyID) + " " + rs.Fields(ProviderName) + " " + rs.Fields(AssessmentPeriod)
Me.Text22 = vcatch
rs.MoveLast
Else
rs.MoveNext
End If
Loop
Me.Tally1.SetFocus
End If
rs.Close
db.Close
End Sub
I have look all over an cannot find anything about displaying all fields. Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要删除 OpenRecordset 第一个参数中的引号:
此外,您需要将 rs.fields() 参数括在引号中:
最后,我不会更改 CurrentDb 的状态。你发现它打开了,就让它打开。
(删除倒数第二行)
所以,稍微清理一下:
You need to remove the quotes from the first argument to OpenRecordset:
Also, you need to surround the rs.fields() argument in quotes:
Finally, I would not change the state of the CurrentDb. You found it open, leave it open.
(remove second to last line)
So, cleaning this up a bit: