要创建一个带有4个下拉列表(产品名称,月份,年份)和一个数字字段需求的用户表单。 用户输入的每月需求应除以4,以将其转换为每周数据并存储在表格中。我能够在excel中实现此功能,而在Access 2016中却无法实现。以下是我的excel vba代码:
Private Sub CmdInsert_Click()
Dim eRow As Long
Dim a As Integer
eRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Select Case Cmonth.Value
Case "Jan": a = 5
While a > 0
Cells(eRow, 2).Value = Cdemand.Value / 5
Cells(eRow, 1).Value = Cproduct.Value
'Cells(eRow, 2).Value = Cdemand.Value
Cells(eRow, 3).Value = Cmonth.Value
Cells(eRow, 4).Value = Cyear.Value
Cells(eRow, 5).Value = a
Cells(eRow, 6).Value = Cells(eRow, 2).Value / 10000
eRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
a = a - 1
Wend
Case "feb": a = 9
While a > 5
Cells(eRow, 2).Value = Cdemand.Value / 4
Cells(eRow, 1).Value = Cproduct.Value
'Cells(eRow, 2).Value = Cdemand.Value
Cells(eRow, 3).Value = Cmonth.Value
Cells(eRow, 4).Value = Cyear.Value
Cells(eRow, 5).Value = a
Cells(eRow, 6).Value = Cells(eRow, 2).Value / 10000
eRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
a = a - 1
Wend
Case "Mar": a = 13
While a > 9
Cells(eRow, 2).Value = Cdemand.Value / 4
Cells(eRow, 1).Value = Cproduct.Value
'Cells(eRow, 2).Value = Cdemand.Value
Cells(eRow, 3).Value = Cmonth.Value
Cells(eRow, 4).Value = Cyear.Value
Cells(eRow, 5).Value = a
Cells(eRow, 6).Value = Cells(eRow, 2).Value / 10000
eRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
a = a - 1
Wend
Case "Apr": a = 18
While a > 13
Cells(eRow, 2).Value = Cdemand.Value / 5
Cells(eRow, 1).Value = Cproduct.Value
'Cells(eRow, 2).Value = Cdemand.Value
Cells(eRow, 3).Value = Cmonth.Value
Cells(eRow, 4).Value = Cyear.Value
Cells(eRow, 5).Value = a
Cells(eRow, 6).Value = Cells(eRow, 2).Value / 10000
eRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
a = a - 1
Wend
Case "May": a = 22
While a > 18
Cells(eRow, 2).Value = Cdemand.Value / 4
Cells(eRow, 1).Value = Cproduct.Value
'Cells(eRow, 2).Value = Cdemand.Value
Cells(eRow, 3).Value = Cmonth.Value
Cells(eRow, 4).Value = Cyear.Value
Cells(eRow, 5).Value = a
Cells(eRow, 6).Value = Cells(eRow, 2).Value / 10000
eRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
a = a - 1
Wend
End Select
End Sub
答案 0 :(得分:0)
访问比创建Excel容易得多。转到创建->表单设计。 在后面添加控件和代码即可实现相同的目标。
此外,可以将数据插入访问表。这使工作易于查询和处理数据。