出现以下错误
代码如下:
Dim ListindexX As Integer, LX As Single, i1 As Integer
On Error GoTo errorhandler
'将选定的序列开始、结束年限范围存放在变量i1中
i1 = Combo1(0).Text & ".年份" & ">=" & CInt(Combo1(1).Text) & "and" & Combo1(0).Text & ".年份" & "<=" & CInt(Combo1(2).Text)
Label3(2).Caption = "序列年限:" & Combo1(1).Text & "~" & Combo1(2).Text & "年。需变动,请选择:"
For i = 0 To List1.ListCount - 1 '从列表框list1(1)内所有字段中,选择一个时间序列
If List1.Selected(i) = True Then
ListindexX = i
Exit For
ElseIf List1.SelCount = 0 Then
MsgBox "您未选择时间序列!"
List1.SetFocus
Exit Sub
End If
Next i
LX = List1.List(ListindexX) '将选中的时间序列名存放在变量XL中
Label2(0).Caption = LX '显示选中的时间序列名
On Error GoTo 1
Adodc1.RecordSource = " select " & Combo1(0).Text & ".年份," & LX & " from " & Combo1(0).Text & " where " & i1
On Error GoTo 1
Adodc1.Refresh '刷新数据库记录集
Set DataGrid1.DataSource = Adodc1 '将DataGrid1 控件绑定到Adodc1上
DataGrid1.Caption = "选定的时间序列数据表"
n = Adodc1.Recordset.RecordCount
ReDim MC(1), X(n - 1)
For i = 0 To n - 1
'当前记录的序号位置AbsolutePosition从1开始取值
Adodc1.Recordset.AbsolutePosition = i + 1
X(i) = Adodc1.Recordset.Fields(1).Value
If i = 0 Then MC(1) = Adodc1.Recordset.Fields(1).Name
Next i
'将"年份"字段的开始、结束值分别显示在标签库label2(1)和label2(2)的caption属性中
Adodc1.Recordset.AbsolutePosition = 1 '当前记录的序号位置AbsolutePosition = 1
Label2(1).Caption = Adodc1.Recordset.Fields(0).Value
Adodc1.Recordset.AbsolutePosition = n '当前记录的序号位置AbsolutePosition =n
Label2(2).Caption = Adodc1.Recordset.Fields(0).Value
MsgBox "您选择的时间序列是:" & Label2(0).Caption & "。现在可以按【关闭】按钮,结束查询了。"
1
Exit Sub
errorhandler:
MsgBox (Err.Description)
End Sub
代码如下:
Dim ListindexX As Integer, LX As Single, i1 As Integer
On Error GoTo errorhandler
'将选定的序列开始、结束年限范围存放在变量i1中
i1 = Combo1(0).Text & ".年份" & ">=" & CInt(Combo1(1).Text) & "and" & Combo1(0).Text & ".年份" & "<=" & CInt(Combo1(2).Text)
Label3(2).Caption = "序列年限:" & Combo1(1).Text & "~" & Combo1(2).Text & "年。需变动,请选择:"
For i = 0 To List1.ListCount - 1 '从列表框list1(1)内所有字段中,选择一个时间序列
If List1.Selected(i) = True Then
ListindexX = i
Exit For
ElseIf List1.SelCount = 0 Then
MsgBox "您未选择时间序列!"
List1.SetFocus
Exit Sub
End If
Next i
LX = List1.List(ListindexX) '将选中的时间序列名存放在变量XL中
Label2(0).Caption = LX '显示选中的时间序列名
On Error GoTo 1
Adodc1.RecordSource = " select " & Combo1(0).Text & ".年份," & LX & " from " & Combo1(0).Text & " where " & i1
On Error GoTo 1
Adodc1.Refresh '刷新数据库记录集
Set DataGrid1.DataSource = Adodc1 '将DataGrid1 控件绑定到Adodc1上
DataGrid1.Caption = "选定的时间序列数据表"
n = Adodc1.Recordset.RecordCount
ReDim MC(1), X(n - 1)
For i = 0 To n - 1
'当前记录的序号位置AbsolutePosition从1开始取值
Adodc1.Recordset.AbsolutePosition = i + 1
X(i) = Adodc1.Recordset.Fields(1).Value
If i = 0 Then MC(1) = Adodc1.Recordset.Fields(1).Name
Next i
'将"年份"字段的开始、结束值分别显示在标签库label2(1)和label2(2)的caption属性中
Adodc1.Recordset.AbsolutePosition = 1 '当前记录的序号位置AbsolutePosition = 1
Label2(1).Caption = Adodc1.Recordset.Fields(0).Value
Adodc1.Recordset.AbsolutePosition = n '当前记录的序号位置AbsolutePosition =n
Label2(2).Caption = Adodc1.Recordset.Fields(0).Value
MsgBox "您选择的时间序列是:" & Label2(0).Caption & "。现在可以按【关闭】按钮,结束查询了。"
1
Exit Sub
errorhandler:
MsgBox (Err.Description)
End Sub
i1 = Combo1(0).Text & ".年份" & ">=" & CInt(Combo1(1).Text) & "and" & Combo1(0).Text & ".年份" & "<=" & CInt(Combo1(2).Text)
Adodc1.RecordSource = " select " & Combo1(0).Text & ".年份," & LX & " from " & Combo1(0).Text & " where " & i1
你自己解释一下,i1 是什么?
1,年份与>=无需连接符号
2,and两边要加空格
3,确定combo1(1).text与combo1(2).text是否为数值型数据
i1 As Integer
是一个字符串, 两者无法相等,自然错误
同时,不需要使用cint,因为你的数据为文本,使用cint会让vb从文本转换为数值,然后又从数值转换为文本,太低效
上班就家里出发直接到公司,没必要从家里出发到北京,再从北京到你公司
你可以使用 dim i1 as string
i1=Combo1(0).Text & ".年份 >=" & Combo1(1).Text & " and " & Combo1(0).Text & ".年份 <=" & Combo1(2).Text)