問題描述
MS‑Access VBA ‑ 如何將文本框使用的當前查詢字段名稱分配給變量 (MS‑Access VBA ‑ How to assign the current query field name used by a textbox to a variable)
我有一個從查詢中獲取記錄的表單。
在這個表單中,我有一些文本框鏈接到查詢字段。
我想將當前值分配給一個變量文本框在 AfterUpdate
事件上使用的查詢字段名稱,如下所示:
Private Sub Texbox1_AfterUpdate()
Dim fldName as Stringf
fldName = Me.RecordSource.Textbox1.Field
End Sub
這當然行不通...
參考解法
方法 1:
The property that you require is ControlSource
.
For example:
Private Sub Texbox1_AfterUpdate()
Dim fldName As String
fldName = Textbox1.ControlSource
End Sub
方法 2:
Private Sub Texbox1_AfterUpdate()
Dim fldName As String
fldName = Textbox1.Value
End Sub
(by Alex、Lee Mac、Sola Oshinowo)