用户界面设计ACCESS版

代码同Excel类似

Dim arr()
Dim ID As String
Dim DJ As Long



Private Sub CommandButton1_Click()



If Me.ListBox1.Value <> "" And Me.ListBox2.Value <> "" And Me.ListBox3.Value <> "" And Me.TextBox1 > 0 Then
Me.ListBox4.AddItem
Me.ListBox4.List(Me.ListBox4.ListCount - 1, 0) = ID
Me.ListBox4.List(Me.ListBox4.ListCount - 1, 1) = Me.ListBox1.Value
Me.ListBox4.List(Me.ListBox4.ListCount - 1, 2) = Me.ListBox2.Value
Me.ListBox4.List(Me.ListBox4.ListCount - 1, 3) = Me.ListBox3.Value
Me.ListBox4.List(Me.ListBox4.ListCount - 1, 4) = Me.TextBox1.Value
Me.ListBox4.List(Me.ListBox4.ListCount - 1, 5) = Me.TextBox1.Value * Me.Label2.Caption
Else

MsgBox "请正确选择商品"
End If

Me.Label5.Caption = Me.Label5.Caption + Me.TextBox1.Value * Me.Label2.Caption



End Sub

Private Sub CommandButton2_Click()
For i = 0 To Me.ListBox4.ListCount - 1
    If Me.ListBox4.Selected(i) = True Then
        Me.Label5.Caption = Me.Label5.Caption - Me.ListBox4.List(i, 5)
        Me.ListBox4.RemoveItem i
    End If
Next
End Sub

Private Sub CommandButton3_Click()
Dim DDID As String
Dim conn As New ADODB.Connection
Dim str As String

If Me.ListBox4.ListCount > 0 Then

DDID = "D" & Format(VBA.Now, "yyyymmddhhmmss")
conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\data\bak.mp3"

'将订单信息抓取到ACCESS'
For i = 0 To Me.ListBox4.ListCount - 1
str = " ('" & DDID & "','" & Date & "','" & Me.ListBox4.List(i, 0) & "'," & Me.ListBox4.List(i, 4) & "," & Me.ListBox4.List(i, 5) & ")"
conn.Execute ("insert into [销售记录] (订单号,日期,产品编号,数量,金额) values" & str)
Next


conn.Close

MsgBox "结算成功"
Unload Me

Else

MsgBox "购物清单为空"
End If

End Sub
Private Sub ListBox1_Click()
Dim dic
Set dic = CreateObject("Scripting.Dictionary")
Me.ListBox2.Clear

For i = LBound(arr) To UBound(arr)
    If arr(i, 2) = Me.ListBox1.Value Then
        dic(arr(i, 3)) = 1
    End If
Next

Me.ListBox2.List = dic.keys
Me.ListBox3.Clear
Me.Label2.Caption = 0

End Sub

Private Sub ListBox2_Click()

Dim dic

Me.ListBox3.Clear
Set dic = CreateObject("Scripting.Dictionary")

For i = LBound(arr) To UBound(arr)
    If arr(i, 2) = Me.ListBox1.Value And arr(i, 3) = Me.ListBox2.Value Then
        dic(arr(i, 4)) = 1
    End If
Next

Me.ListBox3.List = dic.keys
Me.Label2.Caption = 0


End Sub

Private Sub ListBox3_Click()

For i = LBound(arr) To UBound(arr)

    If arr(i, 2) = Me.ListBox1.Value And arr(i, 3) = Me.ListBox2.Value And arr(i, 4) = Me.ListBox3.Value Then
        ID = arr(i, 1)
        DJ = arr(i, 5)
    End If
Next

Me.Label2.Caption = DJ


End Sub

Private Sub UserForm_Activate()
Dim dic
arr = Sheet1.Range("b2:f" & Sheet1.Range("a65536").End(xlUp).Row)
Set dic = CreateObject("Scripting.Dictionary")

For i = LBound(arr) To UBound(arr)
    dic(arr(i, 2)) = 1
Next
Me.ListBox1.List = dic.keys
End Sub
改进的地方1

改进2 -- 抓取产品信息

Private Sub Workbook_Open()
Dim conn As New ADODB.Connection

'每次打开时清空表,保证是最新的数据'
Sheet1.Range("a2:f1000").ClearContents

conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\data\bak.mp3"

'抓取产品信息'
Sheet1.Range("a2").CopyFromRecordset conn.Execute("select * from [产品信息]")

conn.Close
End Sub
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 产品知识面考察 真题 例题分析 例题7.3 DAU代表 。 日用户点击量 月活跃用户数量 日活跃用户数量 网站...
    爱摄影的奥派阅读 14,273评论 4 46
  • 每天进步一点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点~~从开始只能写几句话、模仿别人的观点,到现...
    一个帅气的名字呀阅读 18,504评论 4 31
  • 不知道 排队加塞是不是国人又一个特有的特色 我是来的比较晚了 但是基于我们的传统还是选择了加塞 排在后面的人啊,大...
    利君理疗阅读 1,220评论 0 0
  • 于我而言,中秋是一个多愁善感的日子,就让我自个默默回味多年来中秋带给我的感受吧! 01.忆秦娥.中秋夜 中秋夜,蝉...
    唯一还是我阅读 4,166评论 0 2
  • 书到期了,却没有好好看! 摘一些句子: 1,“意向性是为许多心理状态和事件所具有的这样一种性质,即这些心理状态或事...
    心地目阅读 4,346评论 1 1

友情链接更多精彩内容