You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Access VBA:从lstAvailable移项至lstAssigned后列表框不显示求助

Troubleshooting Your lstAssigned List Box Display Issue

Hey there, let's work through why your lstAssigned list box isn't showing the items you've moved over—even though the data's successfully making it into tblComponents. Here are the most likely fixes:

1. Refresh the lstAssigned Data Source

Access list boxes don't automatically update when the underlying table changes. After inserting your record into tblComponents, you need to explicitly tell lstAssigned to reload its data. Add this line right after your CurrentDb.Execute call:

lstAssigned.Requery

This will force the list box to pull the latest data from its configured RowSource, which should include the newly inserted record.

2. Verify Your lstAssigned RowSource Configuration

Double-check that lstAssigned's RowSource is set up to include the new records you're inserting:

  • Ensure the RowSource query includes all necessary fields from tblComponents (like the component ID and name you want to display).
  • If your RowSource has a WHERE clause (e.g., filtering by the selected machine subsystem), confirm that the new record matches this filter. For example, if your query uses [Machine Subsystem ID] = Forms!YourFormName!listMachineSubSystem.Column(1), make sure your INSERT statement is actually storing the correct nRid value in that field.

3. Check Your INSERT Statement Completeness

From your code snippet, it looks like your sSQL string is cut off. Make sure you're inserting all required fields into tblComponents, especially those that lstAssigned uses to display items. For example, if your table needs both the machine subsystem ID and component ID, your full INSERT should look something like:

sSQL = "INSERT INTO tblComponents ([Machine Subsystem ID], [Component ID]) VALUES (" & nRid & ", " & nEid & ")"

Use dbFailOnError with CurrentDb.Execute to catch any hidden insertion errors that might be happening (even if you think the data is saving):

CurrentDb.Execute sSQL, dbFailOnError

4. Optional: Remove Items from lstAvailable (If Needed)

If you also want the selected items to disappear from lstAvailable after moving, add this line inside your loop (after the INSERT and Requery):

lstAvailable.RemoveItem varRow

Let me know if any of these steps resolve the display issue, or if you need to share more details about your lstAssigned RowSource setup!

内容的提问来源于stack exchange,提问作者user9527824

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:35:52