很奇怪的事情:如果第一个then执行,第二个then就不执行了;如果第一个then不执行,第二个then就执行了。 Private Sub 材料ID_LostFocus() On Error GoTo Err_材料ID_LostFocus Dim i As Integer Dim j As Integer Dim STemp As String Dim STemp1 As String Dim Rs As ADODB.Recordset Dim Rs1 As ADODB.Recordset Set Rs1 = New ADODB.Recordset Set Rs = New ADODB.Recordset STemp = "Select * From 材料数据表" STemp1 = "Select * From 存料数据表" Rs1.Open STemp1, CurrentProject.Connection, adOpenKeyset, adLockOptimistic Rs1.MoveFirst For i = 1 To Rs1.RecordCount If Rs1("材料ID") = Me![材料ID] Then Me![出料单价] = Rs1("存料单价") Exit Sub Else Rs1.MoveNext End If Next i Set Rs1 = Nothing Rs.Open STemp, CurrentProject.Connection, adOpenKeyset, adLockOptimistic Rs.MoveFirst For j = 1 To Rs.RecordCount If Rs("材料ID") = Me![材料ID] Then Me![名称] = Rs("名称") Me![规格] = Rs("规格") Me![单位] = Rs("单位") Exit Sub Else Rs.MoveNext End If Next j Set Rs = Nothing Exit_材料ID_LostFocus: Exit Sub Err_材料ID_LostFocus: MsgBox Err.Description Resume Exit_材料ID_LostFocus End Sub |