Sue said:
I have a field in my table called SSRep which contains a text character N
for
each record (which means that the ssrep report has not been printed for
the
record). After the ssrep report has been printed I want the N to be
replaced
with a P. I am new to vba and not sure what code to use or where the code
should go.
Without knowing when you want the update performed, we couldn't tell you
where you would want to put any VBA. The following Query does what you want,
where the Field is named "HasBeenPrinted".
UPDATE SSRep SET SSRep.HasBeenPrinted = "P"
WHERE [SSRep.HasBeenPrinted] = "N";
Printers, particularly in busy workplaces, can easily jam or experience
other failures, and a report executed and printed may not be complete... it
may be in a stack of crumpled paper inside the printer or have brought the
printer to a halt only partway through. For that reason, I put the "set has
been printed" kind of code (it may well have more complex criteria than the
simple one shown) in code behind a Command Button, and instruct the user not
to press that button until they have reviewed the report output.
DAO code to execute that Query, if you name it qupdHasPrinted, would be:
Private Sub cmdHasPrinted_Click()
On Error GoTo Err_cmdHasPrinted_Click
Dim stDocName As String
stDocName = "qupdHasPrinted"
DoCmd.OpenQuery stDocName, acNormal, acEdit
Exit_cmdHasPrinted_Click:
Exit Sub
Err_cmdHasPrinted_Click:
MsgBox Err.Description
Resume Exit_cmdHasPrinted_Click
End Sub
This code was generated by the Command Button Wizard. All I had to do was
respond to prompts and point and click. Choose Miscellaneous in the First
Dialog, and select Run Query.
If P and N are the only values, you have used a text field to represent a
Yes/No. There is a Yes/No type of field which you could use instead of text,
but the text field works just fine.
Larry Linson
Microsoft Access MVP