Hi Matt
The nice thing about a mile is that it's a finite distance
I'm puzzled about that error, and I wonder if it has something to do with
the boxes in the code below.
Public Function NextWeekday( _
? ? InDate As Date, _
? ? DayOfWeek As VbDayOfWeek _
? ) As Date
Do those appear in your module window? There may be something peculiar
about cutting and pasting from your newsgroup reader into the VBA window.
Try deleting any strange characters or white space at the start of each line
and reinserting space with the Tab key.
You are almost correct with the selection criteria for the SQL statement.
However, instead of referring to Forms!ENTRYFORM2!PO, you can refer to the
value directly, as it is in the scope of the code you are executing:
sql = "Update YourTable set Delivery = NextWeekday(Delivery, " _
& BoatETDDay & ") where PO=" & Me!PO
If PO is a text field then add embedded quotes.
Of course you can check for bad dates and ask for confirmation before
executing your update statement:
If DCount( "*", "YourTable", "PO=" & Me!PO _
& " and Weekday(Delivery)<>" & Me!BoatETDDay) > 0 then
If MsgBox( "Your question", vbYesNo Or vbQuestion) = vbYes Then
... code to update dates
End If
End If
--
Good Luck
Graham Mandeno [Access MVP]
Auckland, New Zealand
Thanks. I get a compile error on the below code saying "Automation
type not supported in visual basic" and it masks out everything from
"Public..." to "...) As Date".
Public Function NextWeekday( _
? ? InDate As Date, _
? ? DayOfWeek As VbDayOfWeek _
? ) As Date
? Dim InDay As VbDayOfWeek
? InDay = Weekday(InDate)
? If InDay = DayOfWeek Then
? ? NextWeekday = InDate
? Else
? ? NextWeekday = InDate - InDay + DayOfWeek _
? ? ? ? + IIf(DayOfWeek < InDay, 7, 0)
? End If
End Function
The field that links the subform to the main form is called PO. The
name of the form is ENTRYFORM2. So would I write "where PO = Forms!
ENTRYFORM2!PO" or "ENTRYFORM2.Form!PO" in the code below where you
have to insert selection criteria?
Dim sql as string
sql = "Update YourTable set Delivery = NextWeekday(Delivery, " _
? ? & BoatETDDay & ") where <insert selection criteria here>"
CurrentDb.Execute sql
But the code changes the dates after the user changes the factory
without asking the user first. Can we first test to see if the dates
are bad and then if bad, have a box that comes up that asks if the
dates should be changed? The box does not have to have the actual
date in it like before, just a message like "Do you want to change the
Delivery dates to the actual week day this factory ships on?"
Thanks. I feel as if I'm taking the mile here.
Matt