2017-12-19 4 views
-1

msアクセス2010のリストボックスから選択したアイテムを別のフォームでテキストボックスに移動する方法リストボックスをクリックすると、リストボックスから。それらはフォームです、私を助けてください。 form1リストボックスをクリックすると、msアクセス2010のリストボックスからテキストボックス内の別のフォームで選択したアイテムを移動する方法

form2

答えて

0

あなたはこれを達成するために、VBAが必要になります。

form1では、form2が開いているかどうかを確認する必要があります。そうでない場合は、コードを停止してform2を開くように指示するか、自動的にフォームを開くようにします。私はあなたがそれを自動的に...

Private sub List0_Click() 'Be sure to change List0 to the listbox control name you have given 
Dim rst   as DAO.Recordset 
Dim strSQL  as String 
'Checks if current form is loaded, opens form if not 
if not currentproject.allforms("form2").isloaded then 
    docmd.openform "Form2",acnormal 
end if 
'Creates query string to find specific record on listbox 
strSQL = "SELECT * " & _ 
     "FROM YourTableNameHere " & _ 
     "WHERE (((YourTableName.YourFieldName) =" & me.List0.value & "));" 
'Opens the recordset from the query string created above 
Set rst = currentdb.openrecordset(strsql) 
'Targets form2 and places values from recordset into form 
With [Forms]![Form2] 
    ![Your form2 control name] = rst![YourfieldNameForValue] 
    'Repeat for each field you wish to place a value in on your form2 
End With 
'Closes recordset and release object in memory 
rst.close 
Set rst = Nothing 
'Validates the recordset is closed and object is released from memory 
EndCode: 
If not rst is nothing then 
    rst.close 
    set rst = nothing 
end if 
end sub 

は再び、現在のデータベースの設計と命名規則に一致するように制御、テーブル、およびフィールド名を変更してくださいしたいと仮定しています。

この機能が動作するかどうかを教えてください。必要に応じて調整します。

+0

フォーム2のコントロール名とfieldNameForValueのどちらを教えてください。私の2番目のフォームはDateAgと呼ばれ、Text0からText12まで6つのテキストボックスがあります。ありがとうございました。 –

関連する問題