|
本帖最后由 hqlin65 于 2018-8-21 10:25 编辑
下面代码执行时类型不匹配,“归属”字段为文本,老师帮忙看一下。谢谢!好象是这句的问题 Me.ComboBox1.List = Application.WorksheetFunction.Transpose(RS.GetRows)
Private Sub UserForm_Initialize()
Set CNN = CreateObject("ADODB.Connection")
Set RS = CreateObject("ADODB.Recordset")
Dim DBPath$, i%, yn&, arr(1 To 16)
'DBPath = ThisWorkbook.Path & "\DB.mdb"
DBPath = " //LS--20170215FKI/结算汇总v2/CF严禁删除/DB.mdb"
On Error GoTo errhandler
'CNN.Open "Provider=Microsoft.Jet.Oledb.4.0;data Source=" & DBPath
CNN.Open "Provider=Microsoft.Jet.Oledb.4.0;data Source=" & DBPath & ";Jet OLEDB:Database Password=" & 2368
If CNN.State = 0 Then MsgBox "连接数据库错误!": Exit Sub
SQL1 = "SELECT DISTINCT 归属 FROM 汇总表"
RS.Open SQL1, CNN, 1, 3
If RS.RecordCount = 0 Then MsgBox "数据库没有任何数据!": Exit Sub
Me.ComboBox1.List = Application.WorksheetFunction.Transpose(RS.GetRows)
Me.ComboBox1.SetFocus
yn = Year(Date)
arr(1) = yn - 1 & "年10月"
arr(2) = yn - 1 & "年11月"
arr(3) = yn - 1 & "年12月"
For i = 4 To 15: arr(i) = yn & "年" & i - 3 & "月": Next
Me.ComboBox2.List = arr
Me.ComboBox3.List = arr
exitsub:
Exit Sub
errhandler:
MsgBox Err.Description
Resume exitsub
End Sub
|
|