A completely different thing than what I thought you wanted to do.
To do this, you'll need to create an append query's SQL statement
("INSERT
INTO ...") for inserting a single record and then loop through that part
of
the code 7 times.
Assuming that you have a variable named datWeekEnded that holds the "new"
final value for WeekEnded field:
Dim lngLoop As Long
Dim strSQL As String
Dim dbs As DAO.Database
Set dbs = CurrentDb
datWeekEnded = DateValue([bxCurrentWeekEndedDate])
For lngLoop = 0 To 6
strSQL = "INSERT INTO [tblWeekOfTable] (PolicyEffectiveDate, [Week
Ended]) " & _
"VALUES (" & DateAdd("d", -lngLoop, datWeekEnded) & ", " &
datWeekEnded & ");"
dbs.Execute strSQL, dbFailOnError
Next lngLoop
dbs.Close
Set dbs = Nothing
--
Ken Snell
<MS ACCESS MVP>
Hi Doug,
Thanks for your help here....I tried this, and it ran correctly. The
oldest
date in PolicyEffectiveDate was removed and a new date was added, plus
it
changed all the dates in Week Ended to 4/17/05. I'm sorry if I didn't
articulate clear enough, chalk it it up to inexperience... I don't
want
to
change or delete anything, I just want to add 7 new records if the date
in
bxCurrentWeekEndedDate doesn't match the latest Week Ended date. For
example, if the latest week ended date is 04/10/2005, then I want to
add
04/11/2005, 04/12/2005, 04/13/2005, 04/14/2005, 04/15/2005, 04/16/2005,
04/17/2005 and have the Week Ended field for these new dates be
04/17/2005.
Thanks for your patience!
:
strSQL = "UPDATE [tblWeekOfTable] SET [PolicyEffectiveDate] =
DateAdd(""d"", 1, [PolicyEffectiveDate] ), [Week Ended] = " &
Format$([bxCurrentWeekEndedDate], "\#mm\/dd\/yyyy\#")
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
message
Hi Ken,
Sorry to be a pain.....
Because of the fields and data types in the table I was trying to
update,
I
couldn't get this to work, it ran, but in such a way that it
corrupted
my
data

. I have redesigned the table to have two fields:
PolicyEffectiveDate (as a date/time type) and Week Ended (also as a
date/time
type) and I have removed Quarter and have it calculating somewhere
else.
My new code looks like this:
If Me![bxCurrentWeekEndedDate].Value = DMax("[Week Ended]",
"tblWeekOfTable") Then
MsgBox "Procede to calculations!", vbOKOnly + vbExclamation
Else
Dim strSQL As String
Dim dbs As DAO.Database
Set dbs = CurrentDb
'''build the query to update the table
strSQL = "UPDATE [tblWeekOfTable] SET [PolicyEffectiveDate] =
DateAdd(""d"", 1, [PolicyEffectiveDate] ),[Week Ended] =
[bxCurrentWeekEndedDate]"
'''run the query that updates the table
dbs.Execute strSQL, dbFailOnError
dbs.Close
Set dbs = Nothing
End If
Currently, if bxCurrentWeekEndedDate = [Week Ended} my message box
pops
up.
If bxCurrentWeekEndedDate = 04/17/2005, I get the error message
"Too
few
parameters. Expected 1." again. My assumption here is that if
bxCurrentWeekEndedDate = 04/17/2005, then the PolicyEffectiveDate
should
update to add the next day, and Week Ended update to be 04/17/2005.
Then
I
guess my loop for 7 days would be something like "when
PolicyEffectiveDate
=
Week Ended, stop the loop?
Thanks!
:
You're welcome.
message
Thank you! You have been most helpful!