|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
帮我看下以下的代码哪里错了。
点运行的时候.提示“用户定义类型未定义”
Private Sub UserForm_Initialize()
ComboBox1.AddItem "一月"
ComboBox1.AddItem "二月"
ComboBox1.AddItem "三月"
ComboBox1.AddItem "四月"
ComboBox1.AddItem "五月"
ComboBox1.AddItem "六月"
ComboBox1.AddItem "七月"
ComboBox1.AddItem "八月"
ComboBox1.AddItem "九月"
ComboBox1.AddItem "十月"
ComboBox1.AddItem "十一月"
ComboBox1.AddItem "十二月"
End Sub
Private Sub CommandButton1_Click()
On Error GoTo 100
'=====判断输入数据规范性====
If TextBox1.Text = "" Or TextBox2.Text = "" Then
MsgBox "终端名称和预销量是必须输入的", 1 + 16, "出错提示"
TextBox1.SetFocus
Exit Sub
End If
'==============查找是否已经有相同工号记录=====================
Dim RS1 As Recordset
Dim DB1 As Database
Set DB1 = OpenDatabase(ThisWorkbook.Path & "\" & "Info.MDB")
Set RS1 = DB1.OpenRecordset(Name:="预销量", Type:=dbOpenDynaset)
With RS1
.FindFirst "终端名称='" & TextBox1.Value & "'"
If Not .NoMatch Then
MsgBox "终端名称 [ " & TextBox1.Value & " ] 的信息已存在,不能重复添加!", 1 + 16, "出错提示"
DB1.Close
Set RS1 = Nothing
Set DB1 = Nothing
Exit Sub
Else
'=============如果未找到工号重复的情况,则新加记录
.AddNew
.Fields("终端名称").Value = Me.TextBox1.Value
.Fields("月份").Value = Me.ComboBox1.Value
.Fields("预销量").Value = Me.TextBox2.Value.Update
' RS1.FindFirst "姓名='" & TextBox2.Value & "'"
MsgBox "增加 [ 终端名称:" & TextBox1.Value & " 预销量:" & TextBox2.Value & " ] 的信息成功!目前共有记录" & RS1.RecordCount & "条", 1 + 16, "添加成功"
End If
End With
'=================添加记录结束============================
DB1.Close
Set RS1 = Nothing
Set DB1 = Nothing
Exit Sub '正常执行结束,跳出 sub
100:
MsgBox "程序执行出错", 1 + 16, "系统提示"
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub |
|