M
MF Scheetz
I've got the following code:
Private Sub PO_AfterUpdate()
Dim cn As ADODB.Connection
Dim BArs As ADODB.Recordset
Dim Rqd, Qty, Iss, box As Integer
Set cn = CurrentProject.Connection
Set BArs = New ADODB.Recordset
BArs.Open "SELECT * FROM [Bird Assembly Table] WHERE [Assembly
TravelerID] = " & Me.PO & " AND [Part Number] = '" & Me.Drawing_Number & "'",
cn, adOpenDynamic, adLockOptimistic
If BArs.EOF Then
'condition 1
box = MsgBox("That Traveler ID doesn't exist.")
Me.PO = ""
Exit Sub
Else
BArs.MoveFirst
Rqd = Me.Qty
Qty = BArs.Fields("Quantity Per AV")
Iss = BArs.Fields("Issued")
If Qty = Iss Then
If Qty = 1 Then
'condition 2
box = MsgBox("A " & Me.Drawing_Number & " has already been
issued to " & Me.PO)
Me.Qty = 0
Me.PO = ""
Else
'condition 3
box = MsgBox(Iss & " " & Me.Drawing_Number & " have already
been issued to " & Me.PO)
Me.Qty = 0
Me.PO = ""
End If
ElseIf Qty <> Iss Then
If Iss = 0 Then
If Rqd > Qty Then
'condition 4
box = MsgBox("The quantity requested is more than
required by the traveler.")
Me.Qty = Qty
Me.Qty.SetFocus
ElseIf Rqd < Qty Then
'condition 5
box = MsgBox(Qty - Rqd & " more " & Me.Drawing_Number &
" will still need to be assigned to this traveler.")
End If
ElseIf Iss > 0 Then
If Rqd > Qty Then
'condition 6
box = MsgBox("The quantity requested is more than
required by the traveler.")
Me.Qty = Qty - Iss
Me.Qty.SetFocus
ElseIf Rqd < Qty Then
'condition 7
box = MsgBox(Qty - Rqd - Iss & " more " &
Me.Drawing_Number & " will still need to be assigned to this traveler.")
End If
End If
End If
End If
BArs.Close
cn.Close
Set BArs = Nothing
Set cn = Nothing
End Sub
During testing of the code, I set in the ADO table:
"Quantity Per AV" = 4
"Issued" = 0
In the form I set Qty to 1.
This should result in condition 5, but condition 4 occurs, incorrect, 1 is
not > 4.
If I change the form Qty to 5 then condition 4 occurs, this is correct, 5 > 4
Any value I place in the form's Qty field, brings condition 4.
Any suggestions?
Thanks,
-Matt
Private Sub PO_AfterUpdate()
Dim cn As ADODB.Connection
Dim BArs As ADODB.Recordset
Dim Rqd, Qty, Iss, box As Integer
Set cn = CurrentProject.Connection
Set BArs = New ADODB.Recordset
BArs.Open "SELECT * FROM [Bird Assembly Table] WHERE [Assembly
TravelerID] = " & Me.PO & " AND [Part Number] = '" & Me.Drawing_Number & "'",
cn, adOpenDynamic, adLockOptimistic
If BArs.EOF Then
'condition 1
box = MsgBox("That Traveler ID doesn't exist.")
Me.PO = ""
Exit Sub
Else
BArs.MoveFirst
Rqd = Me.Qty
Qty = BArs.Fields("Quantity Per AV")
Iss = BArs.Fields("Issued")
If Qty = Iss Then
If Qty = 1 Then
'condition 2
box = MsgBox("A " & Me.Drawing_Number & " has already been
issued to " & Me.PO)
Me.Qty = 0
Me.PO = ""
Else
'condition 3
box = MsgBox(Iss & " " & Me.Drawing_Number & " have already
been issued to " & Me.PO)
Me.Qty = 0
Me.PO = ""
End If
ElseIf Qty <> Iss Then
If Iss = 0 Then
If Rqd > Qty Then
'condition 4
box = MsgBox("The quantity requested is more than
required by the traveler.")
Me.Qty = Qty
Me.Qty.SetFocus
ElseIf Rqd < Qty Then
'condition 5
box = MsgBox(Qty - Rqd & " more " & Me.Drawing_Number &
" will still need to be assigned to this traveler.")
End If
ElseIf Iss > 0 Then
If Rqd > Qty Then
'condition 6
box = MsgBox("The quantity requested is more than
required by the traveler.")
Me.Qty = Qty - Iss
Me.Qty.SetFocus
ElseIf Rqd < Qty Then
'condition 7
box = MsgBox(Qty - Rqd - Iss & " more " &
Me.Drawing_Number & " will still need to be assigned to this traveler.")
End If
End If
End If
End If
BArs.Close
cn.Close
Set BArs = Nothing
Set cn = Nothing
End Sub
During testing of the code, I set in the ADO table:
"Quantity Per AV" = 4
"Issued" = 0
In the form I set Qty to 1.
This should result in condition 5, but condition 4 occurs, incorrect, 1 is
not > 4.
If I change the form Qty to 5 then condition 4 occurs, this is correct, 5 > 4
Any value I place in the form's Qty field, brings condition 4.
Any suggestions?
Thanks,
-Matt