Hi Stephanie
Sorry I haven't replied sooner - just got home from opening night of the
opera (performing!) Don't worry - I'm going to stick to my day job <g>
The problem is that your WHERE clauses are different. You are printing
reports for one bunch of records and updating the DateSent for another
bunch.
Specifically, you are printing the reports where...
"[DateSent] Is Null Or [DateSent] < DateSerial(Year(Date()),1,1)"
and you are updating DateSent where...
"tblAuctionDonors.[AuctionDonorID] = " & [AuctionDonorID]
I think you should do the following:
1. Set a variable with your WHERE condition:
Dim strWhere as String
strWhere = "[DateSent] Is Null Or [DateSent] <
DateSerial(Year(Date()),1,1)"
2. Print the reports using this WHERE condition:
DoCmd.OpenReport "Solicitation Letter", acViewNormal, , strWhere
3. Use the same WHERE condition to update the date sent:
strSQL = "Update tblAuctionDonors Set DateSent=Date() where " _
& strWhere
4. Ask the user to confirm the update of DateSent:
If MsgBox( "Do you want to record these letters as sent?", _
mbYesNo) = mbYes Then
CurrentDb.Execute strSQL, dbFailOnError
To get around the problem of the incorrect date being printed on the
reports, you should change the ControlSource of the textbox on the report
which displays the date from DateSent to =Date().
--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand
Stephanie said:
Graham,
I think I'm doing better now. I think I've combined the table update
with
the report printing. My report now runs with the DateSent already
updated.
However, only the first record in the table is getting updated with
DateSent.
I can't figure out why all records that match the criteria are not
getting
updated with DateSent. I'd appreciate any suggestions.
Private Sub PrintLetter_Click()
'Send to all donors that have not yet been sent letters or
'where the DateSent field is before Jan,1st of that current year.
'Letters marked before that will be sent. Letters after that date will
not.
On Error GoTo Err_PrintLetter_Click
Dim strSQL As String
strSQL = "Update tblAuctionDonors Set tblAuctionDonors.DateSent= Date()
Where tblAuctionDonors.[AuctionDonorID] = " & [AuctionDonorID] & ";"
CurrentDb.Execute strSQL, dbFailOnError
DoCmd.OpenReport "Solicitation Letter", acViewNormal, , "[DateSent] Is
Null
Or [DateSent] < DateSerial(Year(Date()),1,1)"
Dim strSQL1 As String
strSQL1 = "Update tblAuctionDonors Set tblAuctionDonors.DateSent= #" &
Date
& "# Where tblAuctionDonors.[AuctionDonorID] = " & [AuctionDonorID] &
";"
CurrentDb.Execute strSQL1, dbFailOnError
Exit_PrintLetter_Click:
Exit Sub
Err_PrintLetter_Click:
MsgBox Err.Description
Resume Exit_PrintLetter_Click
End Sub
--
Thanks for the help!
:
Hi Stephanie
First, you are building a SQL string, but not using it. You need to
add
the
following line:
CurrentDb.Execute strSQL, dbFailOnError
Second, you can use the Date() function in SQL, which avoids possible
issues
with date formatting in VBA:
strSQL = "Update tblAuctionDonors Set
tblAuctionDonors.DateSent=Date()
where...
Third, I'm not sure if it's what you intend, but you are using a
different
WHERE clause for printing the report from the one you are using to
mark
the
letters as sent.
--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand
Hi, there. I am trying to combine a bit of code and it seems that
it
works
sometimes (it updates the table) and sometimes it doesn't.
With help from the group, I've created a form with a command button.
The
command button runs a report and updates the table, in theory. I've
tested
it, it worked, then I deleted the data from the table and tried
again,
but
it
didn't update the 2nd time. I'm horrible at coding and appreciate
your
suggestions.
Private Sub PrintLetter_Click()
"Sends all donors that have not yet been sent letters or
'where the DateSent field is before Oct.1st of that current year.
'Letters marked before that will be sent. Letters after that date
will
not.
On Error GoTo Err_PrintLetter_Click
DoCmd.OpenReport "Solicitation Letter", acViewNormal, , "[DateSent]
Is
Null
Or [DateSent] < DateSerial(Year(Date()),10,1)"
Dim strSQL As String
strSQL = "Update tblAuctionDonors Set tblAuctionDonors.DateSent= #"
&
Date
&
"# Where tblAuctionDonors.[AuctionDonorID] = " & [AuctionDonorID] &
";"
Exit_PrintLetter_Click:
Exit Sub
Err_PrintLetter_Click:
MsgBox Err.Description
Resume Exit_PrintLetter_Click
End Sub