Office中国论坛/Access中国论坛
标题: [求助]請教各位高手,我的代碼到底哪里錯了,謝謝! [打印本页]
作者: lzx-shmily 时间: 2007-6-6 17:26
标题: [求助]請教各位高手,我的代碼到底哪里錯了,謝謝!
請教各位高手,我的代碼到底哪里錯了,謝謝!好像昨天還能用,今天就不行了,不知道怎麼回事.
我是想從廠內呆滯品尺寸表中選出符合客戶現用機种尺寸表中在公差範圍內的記錄來
[attach]24789[/attach] 繁體+access2000的
Dim a, b, c, d As Single
Dim cn As New ADODB.Connection
Dim rs1 As New ADODB.Recordset
Dim rs2 As New ADODB.Recordset
Dim rs3 As New ADODB.Recordset
Set cn = CurrentProject.Connection
rs1.Open "客戶現用機种尺寸表", cn, 3, 3
rs2.Open "廠內呆滯品尺寸表", cn, 3, 3
rs3.Open "結果表", cn, 3, 3
If IsNull(Me.Text1) = True Then
MsgBox "請輸入一個客戶現用的機种名!", vbOKOnly, "系統提示"
Me.Text1.SetFocus
End
End If
If IsNull(DLookup("品名", "客戶現用機种尺寸表", "品名='" & Me.Text1 & "'")) Then
MsgBox "您輸入了一個不存在的機种名!", vbOKOnly, "錯誤"
Me.Text1 = Null
Me.Text1.SetFocus
End
End If
DoCmd.SetWarnings False
DoCmd.OpenQuery "清空結果表"
DoCmd.SetWarnings True
Me.結果表子表單.Requery
Me.Text3 = DLookup("客戶", "客戶現用機种尺寸表", "品名='" & Forms![表單1].Text1 & "'")
Me.Text5 = DLookup("中徑", "客戶現用機种尺寸表", "品名='" & Forms![表單1].Text1 & "'")
Me.Text7 = DLookup("外徑", "客戶現用機种尺寸表", "品名='" & Forms![表單1].Text1 & "'")
Me.Text9 = DLookup("中柱高", "客戶現用機种尺寸表", "品名='" & Forms![表單1].Text1 & "'")
Me.Text11 = DLookup("板厚", "客戶現用機种尺寸表", "品名='" & Forms![表單1].Text1 & "'")
Me.Text13 = DLookup("中孔", "客戶現用機种尺寸表", "品名='" & Forms![表單1].Text1 & "'")
Me.Text15 = DLookup("攻牙", "客戶現用機种尺寸表", "品名='" & Forms![表單1].Text1 & "'")
Me.Text17 = DLookup("溝槽", "客戶現用機种尺寸表", "品名='" & Forms![表單1].Text1 & "'")
Me.Text19 = DLookup("背凸", "客戶現用機种尺寸表", "品名='" & Forms![表單1].Text1 & "'")
Me.Text21 = DLookup("柱凹", "客戶現用機种尺寸表", "品名='" & Forms![表單1].Text1 & "'")
a = Me.Text5
b = Me.Text7
c = Me.Text9
d = Me.Text11
Do While Not rs2.EOF
If rs2!中徑 > a + 0.05 Or rs2!中徑 < a - 0.15 Then
End
Else
If rs2!外徑 > b + 15 Or rs2!外徑 < b - 4.5 Then
End
Else
If rs2!中柱高 > c + 0.6 Or rs2!中柱高 < c - 0.25 Then
End
Else
If rs2!板厚 > d + 1.7 Or rs2!板厚 < d - 0.7 Then
End
Else
rs3.AddNew
rs3!品名 = rs2!品名
rs3!客戶 = rs2!客戶
rs3!中徑 = rs2!中徑
rs3!外徑 = rs2!外徑
rs3!中柱高 = rs2!中柱高
rs3!板厚 = rs2!板厚
rs3!中孔 = rs2!中孔
rs3!攻牙 = rs2!攻牙
rs3!溝槽 = rs2!溝槽
rs3!背凸 = rs2!背凸
rs3!柱凹 = rs2!柱凹
rs3.Update
rs2.MoveNext
End If
End If
End If
End If
Loop
rs1.Close
rs2.Close
rs3.Close
cn.Close
Set cn = Nothing
Me.結果表子表單.Requery
End Sub
[此贴子已经被作者于2007-6-6 9:29:24编辑过]
作者: lzx-shmily 时间: 2007-6-6 19:37
請大家幫忙看一下,謝謝!
作者: tz-chf 时间: 2007-6-6 20:38
你调试一下,看哪里错了。
作者: lzx-shmily 时间: 2007-6-6 21:40
沒有錯誤提示,但是符合條件的記錄沒有查詢出來
作者: 一点通 时间: 2007-6-6 21:49
条件一个一个地慢慢增加,看问题出在什么地方就OK了
作者: lzx-shmily 时间: 2007-6-6 22:03
還是查不出錯在哪?請問以下這樣有錯嗎,謝謝
Do While Not rs2.EOF
If rs2!中徑 <= a + 0.05 And rs2!中徑 >= a - 0.15 Then
rs3.AddNew
rs3!品名 = rs2!品名
rs3!客戶 = rs2!客戶
rs3!中徑 = rs2!中徑
rs3!外徑 = rs2!外徑
rs3!中柱高 = rs2!中柱高
rs3!板厚 = rs2!板厚
rs3!中孔 = rs2!中孔
rs3!攻牙 = rs2!攻牙
rs3!溝槽 = rs2!溝槽
rs3!背凸 = rs2!背凸
rs3!柱凹 = rs2!柱凹
rs3.Update
rs2.MoveNext
Else
End
End If
Loop
作者: 一点通 时间: 2007-6-6 22:08
不明这段语句要实现的目的
作者: lzx-shmily 时间: 2007-6-6 22:22
就想從rs2中選出符合在rs1中,(rs1!中徑 -0.15 ) <=rs2!中徑 <= (rs1!中徑 + 0.05)的公差範圍內的,把符合條件的記錄查詢出來并新增到rs3中
或者各位高手還有什麼其他的實現辦法,請多多指教,謝謝!
[此贴子已经被作者于2007-6-6 15:28:30编辑过]
作者: lzx-shmily 时间: 2007-6-7 01:34
以下是引用lzx-shmily在2007-6-6 11:37:00的发言:
請大家幫忙看一下,謝謝!
作者: lzx-shmily 时间: 2007-6-7 16:46
或者用查詢可不可以實現這樣的目的呢,請大家幫忙看一下,謝謝!
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) |
Powered by Discuz! X3.3 |