Ms access 单击列表框时,如何以文本框中的另一种形式从ms access 2010中的列表框中移动选定的项目

Ms access 单击列表框时,如何以文本框中的另一种形式从ms access 2010中的列表框中移动选定的项目,ms-access,vba,Ms Access,Vba,如何在ms access 2010中以另一种形式在文本框中移动列表框中的选定项目,单击列表框时,列表框中的每个项目对应一个文本框。这些是表格,请帮我。 您需要VBA才能完成此任务 在form1上,您需要检查form2是否打开,如果没有,您可以让它停止代码并要求用户打开form2,或者让代码自动打开表单。我假设你自动想要它 Private sub List0_Click() 'Be sure to change List0 to the listbox control name you have

如何在ms access 2010中以另一种形式在文本框中移动列表框中的选定项目,单击列表框时,列表框中的每个项目对应一个文本框。这些是表格,请帮我。


您需要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
同样,请确保更改控件、表和字段名称以匹配当前的数据库设计和命名约定


让我知道这是否有效,如果需要,我将进行调整。

您能告诉我哪一个是form2控件名和fieldNameForValue吗?我的第二个表单叫做DateAg,我有6个文本框,从Text0到Text12。非常感谢。