在文本框和子表单中填充列表框(多选) [英] Populating Listbox (Multiple Select) in a textbox and in a subform
问题描述
大家好日子,任何人都可以为我的问题提供帮助
情景是
一个列表框(ID) - 多选 - 每次我选择列表框
下面的出站文本按钮和子表单将在我的表单中检索 -
从另一个表单中获取以下值
i有一个代码,但我需要自定义它,因为每次我在列表框中选择ID时,我在子表单中的值乘以行我的意思是子表单中的值是重复的
这是我的命令按钮中的代码:
''以另一种形式重现价值'
选项比较数据库
选项明确
Dim cboOriginator作为ComboBox
Private Sub cmdtest_Click()
Dim rs As New ADODB.Recordset
Dim cnn As New ADODB.Connection
Dim i As Integer
Dim sSql As String
Dim ssql1 As String
Dim rs1作为新的ADODB.Recordset
设置cnn = CurrentProject.Connection
sSql =" select * from [DR_Table]其中id =" &安培; List20.Value
rs.Open sSql,cnn,adOpenKeyset,adLockOptimistic
如果rs.RecordCount> 0然后
公司= rs!公司
地址= rs!地址
联系人= rs!联系人
指定= rs!指定
Telno = rs!Telno
Faxno = rs!Faxno
rs.Close
ssql1 =" SELECT * FROM [Dr_Detail_Table] WHERE ID =" &安培; List20.Value
rs.Open ssql1,cnn,adOpenKeyset,adLockOptimistic
如果rs.RecordCount> 0然后
我。[JMTPORDETAILSUBFORM] .SetFocus
直到rs.EOF
我。[JMTPORDETAILSUBFORM]![特别] = rs!特别是
我。[JMTPORDETAILSUBFORM]![数量] = rs!数量
我。[JMTPORDETAILSUBFORM]![PartNumber] = rs!PartNumber
我。[JMTPORDETAILSUBFORM]![id] = rs!id
我。[JMTPORDETAILSUBFORM]![flag] = rs!flag
Me.Refresh
''DoCmd.GoToRecord ,, acNewRec
rs.MoveNext
Loop
rs.Close
Else
公司= vbNullString
地址= vbNullString
联系人= vbNullString
指定= vbNullString
Telno = vbNullString
Faxno = vbNullString
结束如果
结束如果
End Sub
这是我在表格中保存的代码
''用于保存
私有子Command23_Click()
Dim rs As New ADODB.Recordset
Dim cnn As New ADODB.Connection
Dim i As Integer
Dim sSql As String
Dim ssql1 As String
Dim rs1 As New ADODB.Recordset
设置cnn = CurrentProject.Connection
sSql =" select * from [POR_Table]其中id =" &安培; List20.Value
rs.Open sSql,cnn,adOpenKeyset,adLockOptimistic
如果rs.RecordCount> 0然后
rs!公司=公司
rs!地址=地址
rs!联系人=联系人
rs !指定=指定
rs!Telno = Telno
rs!Faxno = Faxno
rs.Update
rs 。关闭
ssql1 =" SELECT * FROM [DR_Detail_Table] WHERE ID =" &安培; List20.Value
rs.Open ssql1,cnn,adOpenKeyset,adLockOptimistic
''如果rs.RecordCount> 0然后
我。[JMTPORDETAILSUBFORM] .SetFocus
直到rs.EOF
rs!特殊=我。[JMTPORDETAILSUBFORM]![特别]
rs!数量=我。[JMTPORDETAILSUBFORM]![数量]
rs!PartNumber =我。[JMTPORDETAILSUBFORM]![PartNumber]
''DoCmd.GoToRecord ,, acNewRec
rs.Update
rs.MoveNext
Loop
否则
公司= vbNullString
地址= vbNullString
联系人= vbNullString
指定= vbNullString
Telno = vbNullString
Faxno = vbNullString
结束如果
End Sub
>
非常感谢你提前
Hi guys good day, can anybody help for my problem
The Scenario is
A Listbox (ID) - Multiple Select - everytime i choose in the list box
the following outbound textbutton and subform will retrieve in my form-
the folliwng value will get from another form
i have a code but i need to customize it because everytime i choose ID in my list box my value in subform is multiplying by row i mean the value in subform is duplicating
this my code in my command button:
''For Retrival of Values in another form''
Option Compare Database
Option Explicit
Dim cboOriginator As ComboBox
Private Sub cmdtest_Click()
Dim rs As New ADODB.Recordset
Dim cnn As New ADODB.Connection
Dim i As Integer
Dim sSql As String
Dim ssql1 As String
Dim rs1 As New ADODB.Recordset
Set cnn = CurrentProject.Connection
sSql = "select * from [DR_Table] where id =" & List20.Value
rs.Open sSql, cnn, adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then
Company = rs!Company
Address = rs!Address
Contactperson = rs!Contactperson
Designation = rs!Designation
Telno = rs!Telno
Faxno = rs!Faxno
rs.Close
ssql1 = "SELECT * FROM [Dr_Detail_Table] WHERE ID=" & List20.Value
rs.Open ssql1, cnn, adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then
Me.[JMTPORDETAILSUBFORM].SetFocus
Do Until rs.EOF
Me.[JMTPORDETAILSUBFORM]![Particular] = rs!Particular
Me.[JMTPORDETAILSUBFORM]![Qty] = rs!Qty
Me.[JMTPORDETAILSUBFORM]![PartNumber] = rs!PartNumber
Me.[JMTPORDETAILSUBFORM]![id] = rs!id
Me.[JMTPORDETAILSUBFORM]![flag] = rs!flag
Me.Refresh
''DoCmd.GoToRecord , , acNewRec
rs.MoveNext
Loop
rs.Close
Else
Company = vbNullString
Address = vbNullString
Contactperson = vbNullString
Designation = vbNullString
Telno = vbNullString
Faxno = vbNullString
End If
End If
End Sub
This is my code for Saving in the value in table
''For Saving
Private Sub Command23_Click()
Dim rs As New ADODB.Recordset
Dim cnn As New ADODB.Connection
Dim i As Integer
Dim sSql As String
Dim ssql1 As String
Dim rs1 As New ADODB.Recordset
Set cnn = CurrentProject.Connection
sSql = "select * from [POR_Table] where id =" & List20.Value
rs.Open sSql, cnn, adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then
rs!Company = Company
rs!Address = Address
rs!Contactperson = Contactperson
rs!Designation = Designation
rs!Telno = Telno
rs!Faxno = Faxno
rs.Update
rs.Close
ssql1 = "SELECT * FROM [DR_Detail_Table] WHERE ID=" & List20.Value
rs.Open ssql1, cnn, adOpenKeyset, adLockOptimistic
''If rs.RecordCount > 0 Then
Me.[JMTPORDETAILSUBFORM].SetFocus
Do Until rs.EOF
rs!Particular = Me.[JMTPORDETAILSUBFORM]![Particular]
rs!Qty = Me.[JMTPORDETAILSUBFORM]![Qty]
rs!PartNumber = Me.[JMTPORDETAILSUBFORM]![PartNumber]
''DoCmd.GoToRecord , , acNewRec
rs.Update
rs.MoveNext
Loop
Else
Company = vbNullString
Address = vbNullString
Contactperson = vbNullString
Designation = vbNullString
Telno = vbNullString
Faxno = vbNullString
End If
End Sub
Thank you so much in advance
推荐答案
似乎我的帖子不太清楚,因为我没有得到你们的任何回复我重建了我的措辞
在我的表格中
我有一个列表框和这个列的值(列表框)是ID,用户可以选择多个id
然后是必须显示记录的子表单。在一个表中然后是一个文本框(未绑定)和一个命令按钮来执行
场景是这样的,用户将在列中选择一个ID然后单击命令按钮
文本框将从表中获取值然后在子表单中它也获取另一个表中的记录
Textbox的值正常工作我的问题是在子表单中我注意到每次我选择
一个id并单击命令按钮显示在我的子表单中的记录是重复的,如果我将
列表框属性更改为multiselect(简单)我得到了错误
这是错误运行时错误-2147217900(80040e14)查询表达式中的语法错误(缺少运算符)
''ID ='',
这是我的代码将值重新转换为表格
It seems that my post is not much clear because i dont get any reply from you guys i reconstruct my wording
In my Form
I have a listbox and the Value of this "column" (Listbox) is ID, the user can select a multiple id
then a subform that must display a "record" in a table then a textbox (unbound) and a commandbutton to execute
the scenario is like this, The user will select a ID in column then click the commandbutton
the textbox will get the value from a table then in subform it also get the record in another table
The value for Textbox is working properly my problem is in the subform i noticed that everytime i choose
an id and click the commandbutton the record that display in my subform is duplicating, and if i change the
listbox property into multiselect (simple) i got an error
this is the error " Run-time error -2147217900(80040e14) Syntax error (missing operator)in query expression
''ID ='',
This is my code in Retriving Value into the form
试试这个......
Try this ...
我试过我有错误的代码
运行时错误''2499''
您无法在设计视图中对对象使用GoToRecord操作或方法
然后,如果我单击Debug
指向此代码
DoCmd.GoToRecord ,, acNewRec
hi mary i tried the code i have errors
Run-Time errors ''2499''
You cant use the GoToRecord action or method on an object in Design view
Then if i click Debug
It point to this code
DoCmd.GoToRecord , , acNewRec
这篇关于在文本框和子表单中填充列表框(多选)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!