Hi Matt
Thanks for your patience.
If it doesn't work after this, I'll just write a little reminder to
the user to hand check those dates.
Hey, I'm happy to be patient. Don't give up - we're very close to nailing
this
I definitely think that you should leave BoatETDDay and any joins to
Factorytbl out of your subform. I'll explain later how to handle the
problem of
If EnteredDay <> BoatETDDay Then ...
In fact, I would not include Factorytbl in the RecordSource query of the
main form either.
I assume that you select Factory and Subfactory with combo boxes, right?
Create a query, qrySelectFactory, as follows:
Select FactoryID, FactoryName, BoatETDDay
from Factorytbl order by FactoryName;
Set the properties for both your Factory and Subfactory combo boxes to:
RowSource: qrySelectFactory
ColumnCount: 3
BoundColumn: 1
ColumnWidths: 0;;0
AfterUpdate: =CheckDateChange()
Create a textbox on your main form:
Name: txtBoatETDDay
ControlSource: =Val( Nz( IIf( Subfactory.Column(2) > 0,
Subfactory.Column(2), Factory.Column(2) ), 0 ) )
Visible: No
The complicated ControlSource expression should cover all possibilities of
factory fields being null or BoaETDDay values being missing in a factory
record.
Now you can use txtBoatETDDay, not BoatETDDay in your calculations:
Private Function CheckDateChange()
If txtBoatETDDay > 0 Then
If DCount("*", "OrderDetails", "PO='" & Me!PO _
& "' and Weekday(Delivery)<>" & txtBoatETDDay) > 0 Then
If MsgBox("Do you want to change the Delivery dates " _
& "to the actual week day this factory ships on?", _
vbYesNo Or vbQuestion) = vbYes Then
CurrentDb.Execute "Update OrderDetails " _
& "set Delivery = NextWeekDay(Delivery, " _
& txtBoatETDDay & ") where PO='" & Me!PO & "'", _
dbFailOnError
Me![OrderDetailssub].Form.Requery
End If
End If
End If
End Function
Finally, modify the code in your subform to refer to the textbox on the
parent form:
Private Function Delivery_AfterUpdate()
Dim SuggestedDate as Date, EnteredDay as Integer
Dim BoatETDDay as Integer, msg as String
EnteredDay = Weekday(Delivery)
BoatETDDay = Me.Parent!txtBoatETDDay
If EnteredDay <> BoatETDDay And BoatETDDay > 0 then
SuggestedDate = Delivery - EnteredDay + BoatETDDay _
+ IIf(BoatETDDay < EnteredDay, 7, 0)
msg = Delivery & " is not a " & Format(SuggestedDate, "dddd") _
& vbCrLf & vbCrLf & "Do you wish to change the delivery date to " _
& SuggestedDate & "?"
If MsgBox(msg, vbQuestion Or VbYesNo) = vbYes Then
Delivery = SuggestedDate
End If
End If
End Sub
--
Good Luck
Graham Mandeno [Access MVP]
Auckland, New Zealand