|
Private Sub 货位分配_Click()
On Error GoTo Err_货位分配_Click
Dim i, j As Integer
Dim m, n, k As Integer
Dim strtemp As String
Dim Rs As ADODB.Recordset
Set Rs = New ADODB.Recordset
Dim Rs1 As ADODB.Recordset
Set Rs1 = New ADODB.Recordset
Dim Rs2 As ADODB.Recordset
Set Rs2 = New ADODB.Recordset
Dim Rs3 As ADODB.Recordset
Set Rs3 = New ADODB.Recordset
Dim Rs4 As ADODB.Recordset
Set Rs4 = New ADODB.Recordset
strtemp = "Select * From 进货单"
Rs.Open strtemp, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
strtemp = "Select * From 货号最小查询"
Rs1.Open strtemp, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
strtemp = "Select * From 颜色最小查询"
Rs2.Open strtemp, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
strtemp = "Select * From 序号最小查询"
Rs3.Open strtemp, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
strtemp = "Select * From 款式最小查询"
Rs4.Open strtemp, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
'如果“进货单”为空,则退出
If Rs.RecordCount <= 0 Then
Exit Sub
End If
Rs.MoveFirst
For i = 0 To Rs.RecordCount - 1
cunzai = False
If Rs1.RecordCount < 1 Then
cunzai = False
Else
'判断记录库存中货号最小记录,是则将仓位填入进货单中
Rs1.MoveFirst
For j = 0 To Rs1.RecordCount - 1
If Rs1("货号") = Rs("货号") Then
Rs("货位") = Rs1("货位")
Rs.Update
cunzai = True
Exit For
Else
Rs1.MoveNext
End If
Next j
End If
'不存在,则按颜色/序号/款式搜索仓位,填入新仓位到空仓位
If cunzai = False Then
Rs2.MoveFirst
For m = 0 To Rs2.RecordCount - 1
If Rs2("颜色货号") = Left(Rs("货号"), 12) Then
Rs("货位") = Rs2("货位")
Rs.Update
cunzai = True
Exit For
Else
Rs2.MoveNext
End If
Next m
MsgBox "货位分配已成功", vbInformation, "分配成功"
ElseIf cunzai = False Then
Rs3.MoveFirst
For n = 0 To Rs2.RecordCount - 1
If Rs2("序号货号") = Left(Rs("货号"), 9) Then
Rs("货位") = Rs2("货位")
Rs.Update
cunzai = True
Exit For
Else
Rs2.MoveNext
End If
Next n
MsgBox "货位分配已成功", vbInformation, "分配成功"
ElseIf cunzai = False Then
Rs4.MoveFirst
For k = 0 To Rs4.RecordCount - 1
If Rs4("款式货号") = Left(Rs("货号"), 6) Then
Rs("货位") = Rs4("货位")
Rs.Update
cunzai = True
Exit For
Else
Rs4.MoveNext
End If
Next k
MsgBox "货位分配已成功", vbInformation, "分配成功"
End If
Rs.MoveNext
Next i
'Set Rs = Nothing
Set Rs1 = Nothing
Set Rs2 = Nothing
Set Rs3 = Nothing
Set Rs4 = Nothing
'Me![进货单管理 子窗体].Requery
MsgBox "货位分配已成功", vbInformation, "分配成功"
Exit_货位分配_Click:
Set Rs = Nothing
Set Rs1 = Nothing
Exit Sub
Err_货位分配_Click:
MsgBox Err.Description
Resume Exit_货位分配_Click
End Sub
请各位老师帮忙看看,我想得到如果查找货号=假,
那么选择颜色进行查找,如果颜色=假,那么选择序号
进行查找,如果序号等于假,那么选择款式进行查找,
在上面的语句中运行,如果货号查找不到,就选择颜色,
其他序号和款式则不能显示,附上附件,先谢谢老师! |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|