+ -
当前位置:首页 → 问答吧 → vb access 运行窗体时为何总是显示参数不足,期待是1、

vb access 运行窗体时为何总是显示参数不足,期待是1、

时间:2011-12-14

来源:互联网

这是一窗体成为活动窗体的代码
Private Sub Form_Activate()
  Dim X0 As Long
  Dim Y0 As Long
  '让窗体居中
  X0 = Screen.Width
  Y0 = Screen.Height
  X0 = (X0 - Me.Width) / 2
  Y0 = (Y0 - Me.Height) / 2
  Me.Move X0, Y0
  Dim inty As Integer '当前年份
  Dim intm As Integer '当前月份
  Dim intd As Integer '当前日期
  inty = Year(Date)
  intm = Month(Date)
  intd = Day(Date)
  Dim sqlbuy As String
  Dim sqlfctotal As String '各客户入库总金额
  Dim sqltotal As String '总入库金额
  Dim rs_check As New ADODB.Recordset
  Dim rs_fctotal As New ADODB.Recordset
  Dim rs_total As New ADODB.Recordset
  rs_check.CursorLocation = adUseClient '设置游标方式
  rs_fctotal.CursorLocation = adUseClient
  rs_total.CursorLocation = adUseClient

。。。。。

后面的代码是关于选项卡的。有四个选项卡。每个选项卡上有两个datagrid,分别显示两种数据。每个选项卡有两个adodc用来连接数据库,就有8个adodc.
运行时出错提示依次是提示adodc8,adodc6,adodc4,adodc2出错,内容就是参数不足,期待是1 。退出时也会出现相同的错误提示。


看了很多帖子,说的数据库中的字段、数据类型可能不一致,但是去对比了。是一致的。

我在代码上注释断点,出错就是显示在正式执行选项卡的代码前。我都找不出错误的地方了、有的贴友说在数据库中查看是不是变量的混淆。我不会这个。我的数据库是access2007的。。看看吧。。。怎么解决啊。

作者: myyangli88   发布时间: 2011-12-14

你的sql语句有问题。

作者: chinaboyzyq   发布时间: 2011-12-14

Case 1
  SSTabbuy.TabEnabled(0) = False
  SSTabbuy.TabEnabled(1) = True
  SSTabbuy.TabEnabled(2) = False
  SSTabbuy.TabEnabled(3) = False
  If frmbuy2.Text1.Text = "" And frmbuy2.Text2.Text = "" Then
  sqlbuy = "select * from goods where 入库年 =" & inty _
  & "and 入库月=" & intm & " order by 客户名称,总金额 desc"
  rs_check.Open sqlbuy, conn, adOpenKeyset, adLockPessimistic
  Adodc3.RecordSource = sqlbuy
  Adodc3.Refresh
  DataGrid3.ReBind
  If rs_check.EOF = True Then
  Adodc4.RecordSource = sqlbuy
  Adodc4.Refresh
  DataGrid4.ReBind
  Text2.Text = 0
  MsgBox "您本月没有入库产品!", vbOKOnly + vbInformation, "注意"
  rs_check.Close
   
  Exit Sub
  End If
  Else ’没有执行下面的代码。不管查询里面有没有数据,都是执行的上面的代码
  sqlbuy = "select * from goods where 入库年 =" & inty _
  & "and 入库月=" & intm & " and 客户编号='" & frmbuy2.Text1.Text & "' and 型号='" & frmbuy2.Text2.Text & "'order by 客户名称,总金额 desc"
  rs_check.Open sqlbuy, conn, adOpenKeyset, adLockPessimistic
  Adodc3.RecordSource = sqlbuy
  Adodc3.Refresh
  DataGrid3.ReBind
  If rs_check.EOF = True Then
  Adodc4.RecordSource = sqlbuy
  Adodc4.Refresh
  DataGrid4.ReBind
  Text2.Text = 0
  MsgBox "您本月没有入库产品!", vbOKOnly + vbInformation, "注意"
  rs_check.Close
   
  Exit Sub
  End If
  End If
  rs_check.Close
  sqlfctotal = "select 客户编号,sum(总金额) as 各客户入库总金额 " _
  & "from goods where 入库年 =" & inty & "and 入库月=" & intm _
  & " group by 客户名称 "
  rs_fctotal.Open sqlfctotal, conn, adOpenKeyset, adLockPessimistic
  Adodc4.RecordSource = sqlfctotal
  Adodc4.Refresh
  DataGrid4.ReBind
  rs_fctotal.Close
  sqltotal = "select sum(总金额) as 入库总金额 from goods where " _
  & " 入库年 =" & inty & "and 入库月=" & intm
  rs_total.Open sqltotal, conn, adOpenKeyset, adLockPessimistic
  Text2.Text = rs_total.Fields(0)
  rs_total.Close
   

这是其中一个选项卡的代码。你看看。我刚刚发现根本就没有执行else后面的语句、、、郁闷

作者: myyangli88   发布时间: 2011-12-14

热门下载

更多