vba - How to display table values for a single event, multiple rows for a single attribute, in text boxes, as if I were using a crosstab query
问题描述
I have a form that should display a slope value for different transects on a plot, all tied to a single event, using different text boxes.
For example: There is a monitoring event record. The StandTransectSlope table has 3 rows for one EventID: slope for the UP (upper, ID=1) transect, slope for the BL (bottom left, ID=2) transect, slope for the BR (bottom right, ID=3) transect.
I have 3 text boxes: one box to display the slope value for each of the transects (1-3).
I did have a crosstab query behind this form so that I could, easily, assign those different slope values from each row by the transect name. But then I found out the crosstab query is not updateable. Users need to be able to add new data, as well as view data already entered. How can I code to allow this?
Currently, I have the following code on the Form_Load event (I'll have to also add code for AfterUpdate for the form):
Private Sub Form_Load()
Dim ID As Integer
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Set db = CurrentDb
strSQL = "SELECT * FROM xrefCOMN_StandEventTransectSlope WHERE EventID =" & Me.EventID
Set rs = db.OpenRecordset(strSQL)
'Set values for slope text boxes by ID
Select Case ID
Case 1
Me.txtSlopeUP.Value = DLookup("Slope", "xrefCOMN_StandEventTransectSlope", "EventID=" & Me.EventID)
Case 2
Me.txtSlopeBR.Value = DLookup("Slope", "xrefCOMN_StandEventTransectSlope", "EventID=" & Me.EventID)
Case 3
Me.txtSlopeBL.Value = DLookup("Slope", "xrefCOMN_StandEventTransectSlope", "EventID=" & Me.EventID)
Case Else
'Nothing
End Select
End Sub
解决方案
推荐阅读
- python - 使用自定义热图制作子图
- .net - .net framework 4.0 下载失败,错误代码为 0x800c0006
- java - 我如何才能从 firebase ML Kit 人脸检测中获取情感?
- asp.net-core - Microsoft.HPC.SDK 可以在 blazor 服务器应用程序中使用吗?
- sql - 使用 SQL 在 MS Access 中生成数字 1 到 1000000
- dns - 是否需要 DNS 缓存管理器才能准确测试我的 Web 应用程序的性能?
- android - 如何将 .wav 格式编码为 Base64 以用于云语音 http api android?
- jenkins - JFrog Xray 可以在 Jenkins 作业期间使用来自 Bitbucket 的工件扫描二进制文件吗
- shell - 如何使用多个 shell 命令设置 Gitlab ci 阶段
- swift - 使用 CompositionalLayout 时如何将 UICollectionView 部分固定到导航栏(最好通过代码,但其他选项也不错)