如何在VB访问数据库中填充组合框上的文本框值 [英] How to populate text box values on combobox in VB access database

查看:83
本文介绍了如何在VB访问数据库中填充组合框上的文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我想知道如何在vb访问数据库的组合框中填充文本框值。



或如何在表单加载事件的组合框中获取数据库值。



数据库值通过表单2和组合存储在另一个表中框放在第一个表格上,将整个数据输入数据库。



我也试图在复选框按钮上弹出日期提醒。



提前致谢



我尝试过:



这是我的代码:



Hi friends,

I want to know about how to populate text box values on combo box in vb access database.

or how to get database values on combo box at form load event.

database values are stored in another table by form 2 and the combo box is placed on 1st form which enters the whole data into database.

also i am trying to make a popup for date reminder on check box button.

Thanks in advance

What I have tried:

here is my code:

Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset

Private Sub cmdExit_Click()
   End
End Sub

Private Sub CmdSave_Click()
   Set rs = New ADODB.Recordset
   rs.AddNew
   rs.Fields(CompanyName).Value = TxtCompanyName.Text
   Clear
End Sub

Private Sub UserForm_Click()
   con.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Users\mahtab.ali\Documents\NoticeBook.mdb;Persist Security Info=False"
   rs.Open "Select * from CompanyName", con, adOpenDynamic, adLockPessimistic
   Me.fillcombo
End Sub

Sub Clear()
   ComboBox1.Value = ""
   TxtCompanyName.Text = ""
End Sub

Sub fillcombo()
   Do Until rs.EOF
      ComboBox1.AddItem rs!CompanyName
      rs.MoveNext
   Wend
End If
End Sub

推荐答案

我找到了一些有用的代码,并根据我的要求进行了更改,并且它有效。它在组合框中显示了以新公司文本框形式更新的值。



i've found some helpful code and changed it as my requirement and it works. it is showing values in combobox which were updated in new company textbox form.

Private Sub Form_Initialize()
On Error GoTo Form_Initialize_Err
    Dim cnn As New ADODB.Connection
    Dim rst As New ADODB.Recordset
    cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\Database Folder\Notice Book\Notice Book project\database\Notice Book.mdb;Persist Security Info=False"
    rst.Open "SELECT DISTINCT [CompanyName] FROM CompanyDetails ORDER BY [CompanyName];", _
             cnn, adOpenStatic
    rst.MoveFirst
    With Me.CmbSelectCompany
        .Clear
        Do
            .AddItem rst![CompanyName]
            rst.MoveNext
        Loop Until rst.EOF
    End With
Form_Initialize_Exit:
    On Error Resume Next
    rst.Close
    cnn.Close
    Set rst = Nothing
    Set cnn = Nothing
    Exit Sub
Form_Initialize_Err:
    MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "Error!"
    Resume Form_Initialize_Exit
End Sub



感谢您的时间和帮助:)


thanks for ur time and help :)


这篇关于如何在VB访问数据库中填充组合框上的文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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