職場で自分のグループのMS Accessカリキュラム管理ツールを構築しました。私は、エンドユーザーが特定のコースのトレーニング教材を追加できるようなフォームを用意しています。フォームのフィールドの1つは、その資料が使用されている特定の病院を要求します。このフォームに入力するには、ユーザーがマルチセレクションできるシステム内のすべての病院のリストを含むフォーム(「sbfrmcoursematerialsite」)を表示するボタンをクリックします。MS Access VBA:サブフォームを正しく参照する
SELECT pklistEntSites.Site FROM pklistEntSites UNION SELECT " [Enterprise]" FROM pklistEntSites
ORDER BY pklistEntSites.Site;
この複数選択がtxtSiteという名前txtBoxの制御源である(病院の略語を連結し、「sbfrmTrainingElements」の「サイト」フィールドに挿入する文字列を作成します。フォームは、このSQLコードを使用して移入されます)。私の問題は、 "sbfrmcoursematerialsite"のOKボタンをクリックすると、この操作を実行できないというエラーが表示されることです。 "sbfrmcoursematerialsite"フォームに含まれる私のVBAコードは以下の通りです。連結機能は動作していますが、コード内の太字の行にエラーが発生します。データを追加したいサブフォームを適切に参照していませんか?
Private Sub cmdOk_Click()
Dim teID As Integer
Me.Refresh
teID = Me.txtTrainingElementID 'Document Training Element ID
DoCmd.SetWarnings False
'Update the Site field in tblTrainingElements for the specific training element
'DoCmd.RunSQL "UPDATE tblTrainingElements SET [Site] = '" & Me.txtSelectedSites & "' WHERE [Training Element ID] = " & teID & ";"
'Debug.Print Me.txtSite.Value
Debug.Print [Forms]![frmFullCourseInfo]![sbfrmTrainingElements]! [Site].Value
**[Forms]![frmFullCourseInfo]![sbfrmTrainingElements]![Site].Value = Me.txtSelectedSites**
DoCmd.SetWarnings True
'Close the site select form
DoCmd.Close
End Sub
Private Sub Form_Load()
'Show current site selection
Me.txtSelectedSites = [Forms]![frmFullCourseInfo]! [sbfrmTrainingElements]![Site]
'Pass the training element ID from the last screen to current form
Dim i As Integer
i = CInt(Me.OpenArgs)
Me.txtTrainingElementID.Value = i
End Sub
Private Sub lboAllSites_Click()
Dim strSelected As String
Dim varItem As Variant
With Me.lboAllSites
For Each varItem In .ItemsSelected
strSelected = strSelected & "," & .ItemData(varItem)
Next varItem
Me.txtSelectedSites = Mid(strSelected, 2)
End With
End Sub
'[Forms]![frmFullCourseInfo]![sbfrmTrainingElements] .Form![Site]' – Parfait
@Parfait: 'sbfrmTrainingElements'はサブフォームの名前でなければならないことを強調してくださいフォーム 'frmFullCourseInfo'の_control_ – Gustav