MS Access将项目添加到组合框(如果不在列表中) [英] MS access add item to combo box if non in list

查看:62
本文介绍了MS Access将项目添加到组合框(如果不在列表中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个访问表,我想知道如何在组合框中添加项目(如果那里没有). 我的组合框处于值模式.

I have an access form, i want to know how to add item in combo box if there is not in there. my combo box is in value mode.

推荐答案

不幸的是,如果不将表单更改为设计模式并添加新值,就无法永久更改行源.用代码可以做到这一点,但是当人们在工作时,这不是一个好主意.最简单的方法是创建一个小表并将值添加到该表中.关闭表单后,新值将被保存.

Unfortunately you cannot change the rowsource permanently without changing the form to design mode and adding the new value. It is possible to do this with code, but it is not a good idea when people are working. The easiest thing is to create a small table and add the values to that. New values will then be saved when you close the form.

艾伦·布朗(Allen Browne)对如何执行此操作进行了说明: http://allenbrowne.com/ser-27 .html

Allen Browne has a description of how to do this : http://allenbrowne.com/ser-27.html

这是他展示的想法之一:

This is one of the ideas he shows:

Private Sub CategoryID_NotInList(NewData As String, Response As Integer)
    Dim strTmp As String

    'Get confirmation that this is not just a spelling error.
    strTmp = "Add '" & NewData & "' as a new product category?"
    If MsgBox(strTmp, vbYesNo + vbDefaultButton2 + vbQuestion, "Not in list") = vbYes Then

        'Append the NewData as a record in the Categories table.
        strTmp = "INSERT INTO Categories ( CategoryName ) " & _
            "SELECT """ & NewData & """ AS CategoryName;"
        DBEngine(0)(0).Execute strTmp, dbFailOnError

        'Notify Access about the new record, so it requeries the combo.
        Response = acDataErrAdded
    End If
End Sub

这篇关于MS Access将项目添加到组合框(如果不在列表中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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