我想设计一个数据库.前面的条件连接到别的数据库,可以显示的,  再点击确定按钮后, 切削深度\ 每齿进给量 \切削速度  会显示结果.但我不知道错在那里
Private Sub Command1_Click()切削深度
 Dim a As Single
 Dim b As Single
 Dim c As Single
 Dim d As Single
 Dim m As Single
 Dim n As Single
 Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\桌面\任雪艳\任雪艳毕设\切削用量表.mdb;Persist Security Info=False"
 Adodc1.RecordSource = "select * From 切削用量表 where 刀具名称='" + Text1.Text + "' And 刀具材料 ='" + Text2.Text + "' And 刀具直径=" + Text3.Text + " And 刀具齿数 =" + Text4.Text + " and 工件牌号='" + Form6.Text3.Text + "'"
  Adodc1.Refresh
  DataGrid1.Refresh
  On Error Resume Next
 a = Adodc1.Recordset!切削深度
 c = Adodc1.Recordset!每齿进给量
 m = Adodc1.Recordset!切削速度
  Do
  Adodc1.Recordset.MoveNext
  b = Adodc1.Recordset!切削深度
  d = Adodc1.Recordset!每齿进给量
  n = Adodc1.Recordset!切削速度
  If a < b Then
  a = b
  c = d
  m = n
  End If
 Loop While Not Adodc1.Recordset.EOF
  Adodc1.Refresh
  DataGrid1.Refresh
   Text10.Text = a
   Text8.Text = m
   Text9.Text = cEnd Sub

解决方案 »

  1.   


    Adodc1.RecordSource = "select * From 切削用量表 where 刀具名称 ='" & _
    Text1.Text & "' And 刀具材料 ='" & Text2.Text & "' And 刀具直径=" & Val(Text3.Text) & " And 刀具齿数 =" & Val(Text4.Text) & " and 工件牌号='" + Form6.Text3.Text + "'"
      

  2.   

    Private Sub Command1_Click()切削深度 
    Dim a As Single 
    Dim c As Single 
    Dim m As Single Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\桌面\任雪艳\任雪艳毕设\切削用量表.mdb;Persist Security Info=False" 
    Adodc1.RecordSource = "select * From 切削用量表 where 刀具名称='" + Text1.Text + "' And 刀具材料 ='" + Text2.Text + "' And 刀具直径=" + Text3.Text + " And 刀具齿数 =" + Text4.Text + " And 工件牌号='" + Form6.Text3.Text + "' Order By 切削深度 Desc" Adodc1.Refresh DataGrid1.Refresh 
    On Error Resume Next 
    a = Adodc1.Recordset!切削深度 
    c = Adodc1.Recordset!每齿进给量 
    m = Adodc1.Recordset!切削速度 Text10.Text = a 
    Text8.Text = m 
    Text9.Text = c End Sub 
      

  3.   

    Private Sub Command1_Click()
        Dim a As Single
        Dim b As Single
        Dim c As Single
        Dim d As Single
        Dim m As Single
        Dim n As Single
        Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\桌面\任雪艳\任雪艳毕设\切削用量表.mdb;Persist Security Info=False"
        strSQL = "select * From 切削用量表 where 1=1 "
            If Text1.Text <> "" Then strSQL = strSQL + " and 刀具名称='" + Text1.Text + "'"
            If Text1.Text <> "" Then strSQL = strSQL + " and 刀具材料 ='" + Text2.Text + "'"
            If Text1.Text <> "" Then strSQL = strSQL + " And 刀具直径=" + Text3.Text
            If Text1.Text <> "" Then strSQL = strSQL + " and 刀具齿数 =" + Text4.Text
            If Text1.Text <> "" Then strSQL = strSQL + " and 工件牌号='" + Form6.Text3.Text + "'"
        Adodc1.RecordSource = strSQL
        Adodc1.Refresh
        DataGrid1.Refresh
        
        On Error Resume Next
        a = Adodc1.Recordset!切削深度
        c = Adodc1.Recordset!每齿进给量
        m = Adodc1.Recordset!切削速度
        Do
            Adodc1.Recordset.MoveNext
            b = Adodc1.Recordset!切削深度
            d = Adodc1.Recordset!每齿进给量
            n = Adodc1.Recordset!切削速度
            If a < b Then
                a = b
                c = d
                m = n
            End If
        Loop While Not Adodc1.Recordset.EOF
        Adodc1.Refresh
        DataGrid1.Refresh
        Text10.Text = a
        Text8.Text = m
        Text9.Text = c
    End Sub
      

  4.   

    On Error Resume Next
    把这句话去掉,应该能发现哪里错了
      

  5.   

    按照8楼的改,并且添加一个"order by 切削深度",选择第一条就可以了(不知道Access是否支持"Top 1")。
      

  6.   

        Do While Not Adodc1.Recordset.EOF
            Adodc1.Recordset.MoveNext
            b = Adodc1.Recordset!切削深度
            d = Adodc1.Recordset!每齿进给量
            n = Adodc1.Recordset!切削速度
            If a < b Then
                a = b
                c = d
                m = n
            End If
        Loopdo 会多做一次
    do while 仅仅符合条件才做