laoyebin

 

 

ACCESS数据库界面

 

EXCEL的窗体界面

 

窗体中的代码:

Private Sub ComboBox1_Change()
    Dim cn As Object, sql$, arr, i&
    Set cn = CreateObject("adodb.connection")
    cn.Open "provider=Microsoft.jet.OLEDB.4.0;data source=" & ThisWorkbook.Path & "\后台.mdb"
    Me.ListBox1.Clear
    sql = "select 车间,产品,价格 from 产品 where 车间=\'" & Me.ComboBox1.Text & "\'"
    arr = cn.Execute(sql).getrows
    Me.ListBox1.BoundColumn = 2
    For i = 0 To UBound(arr, 2)
        Me.ListBox1.AddItem arr(1, i) & vbTab & arr(2, i)
    Next
    cn.Close
    Set cn = Nothing
End Sub

Private Sub UserForm_Initialize()
    Dim arr
    Dim cn As Object, sql$
    Set cn = CreateObject("adodb.connection")
    cn.Open "provider=Microsoft.jet.OLEDB.4.0;data source=" & ThisWorkbook.Path & "\后台.mdb"
    sql = "select distinct 车间 from 产品"
    arr = cn.Execute(sql).getrows
    Me.ComboBox1.List = WorksheetFunction.Transpose(arr)
    Me.ComboBox1.Value = arr(0, 0)
    cn.Close
    Set cn = Nothing
End Sub

 

 

原文件可以去下面地址下载:

http://u.115.com/file/f7df8e035b

分类:

技术点:

相关文章:

  • 2021-12-29
  • 2021-12-18
  • 2021-12-18
  • 2021-10-02
  • 2021-06-05
  • 2022-01-01
  • 2021-11-03
  • 2021-11-12
猜你喜欢
  • 2021-09-01
  • 2021-11-03
  • 2021-10-05
  • 2021-09-01
  • 2021-12-19
  • 2021-12-17
  • 2021-05-18
相关资源
相似解决方案