添加值多列列表框在Access 07 VBA [英] Add Values to a multi column listbox in Access '07 VBA

查看:1727
本文介绍了添加值多列列表框在Access 07 VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个初学者到Access '07。我目前工作的一个食堂查询系统。在添加/修改项目屏幕上,我有一个组合框从一个表tblSampleData包含项目,价格,QtyAvailable场平局值。我从组合(这是bascially所有可用的项目列表)传输所需的物品列表框(其中包含了用户想要的物品)通过转移按钮的点击。无论是组合和清单都有列标题。如何创建另一行,这是不相关的任何表,在列表框中,称数量,用户可以输入自己的项目的数量?

I am a beginner to Access '07. I currently am working on a Canteen Query System. In the Add/Modify Item screen, I have a combobox which draws values from a table tblSampleData which contains Item, Rate, QtyAvailable fields. I have the required items transferred from the combo (which is bascially a list of all available items) to a listbox (which contains the items the user wants) through the click of a transfer button. Both the combo and the list have column headers. How do you CREATE ANOTHER row, which is not associated to any table, in the listbox, called Quantity, where the user can enter the quantity of his item?

急求助会祝贺。 要解决这个问题的任何其他方式将被称赞。 此外,请随时提出对此有任何疑问,如果你不明白。

Urgent help will be congratulated. Any other way to solve this will be complimented. Also, Please feel free to ask ANY queries regarding this, if you didn't understand.

问候, 小号桑迪普

推荐答案

如果我正确地理解您的需求,您将需要一个文本框添加到您的形式,这样用户可以指定数量时,他们选择一个项目。

If I understand your requirements correctly, you will need to add a textbox to your form so the user can specify a quantity when they select an item.

[假设]

- >表的数据:我的[tblSampleData]看起来是这样的:

--> Table data: My [tblSampleData] looks like this:

ID  Item    Rate    QtyAvailable
1   Item1   Rate1   3
2   Item2   Rate2   5

- >组合框:在绑定列组合框是 1 ,(隐藏)第一列,即[ID]。

--> Combo box: The Bound Column of the combo box is 1, the (hidden) first column, which is [ID].

- >数据绑定:组合框有一个行来源(tblSampleData),但没有控制源 。列表框是完全绑定。

--> Data bindings: The combo box has a Row Source (tblSampleData), but no Control Source. The list box is completely unbound.

如果您的情况是不同的,他们就需要调整样本code,以适应。

If your situation is different they you'll need to tweak the sample code to suit.

[/假设]

我创建了一个测试的形式,看起来像这样第一次打开时:

I created a test form that looks like this when it is first opened:

形式背后的VBA code是这样的:

The VBA code behind the form is this:

Option Compare Database
Option Explicit

Private Sub btnTransfer_Click()
Dim cdb As DAO.Database, rst As DAO.Recordset, qtySelected As Long
Set cdb = CurrentDb
Set rst = cdb.OpenRecordset("SELECT * FROM tblSampleData WHERE ID=" & Me.cbxItems.Value, dbOpenSnapshot)
qtySelected = Val(Nz(Me.txtQty.Value, 0))
If qtySelected <= 0 Then
    MsgBox "Please specify a (positive) quantity.", vbExclamation
Else
    If qtySelected <= rst!QtyAvailable Then
        Me.lstSelected.AddItem rst!ID & ";" & rst!Item & ";" & rst!Rate & ";" & qtySelected
    Else
        MsgBox "Quantity selected exceeds quantity available.", vbExclamation
    End If
End If
rst.Close
Set rst = Nothing
Set cdb = Nothing
End Sub

Private Sub Form_Load()
Do While Me.lstSelected.ListCount > 0
    Me.lstSelected.RemoveItem 0
Loop
Me.lstSelected.AddItem ";Item;Rate;QtySelected"
End Sub

用户从组合框中选择项目...

The user selects the item from the combo box...

...输入在文本框中的数量...

...enters the quantity in the text box...

...,然后点击传送按钮,将项目+选择的数量移动到列表框中:

...and then clicks the "Transfer" button to move the item + selected quantity into the list box:

这篇关于添加值多列列表框在Access 07 VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆