Data entry then print?

  • Thread starter Thread starter Randy
  • Start date Start date
R

Randy

Whenever I enter the record and then go to a report based on that
record the record does not show up in the report it is blank. Its
there but it appears that the table has not accepted the record when I
print. If I go back and then select another record and go back to the
last record it prints the selected record will usually work. How can I
get it to accept the last record keyed so I can print it?
 
Here is code that you can add to a button to print a report and only include
the active record. Not sure if that is what you are trying to do.

BUT...

You DO need the section that with the comments "save any edits"



Private Sub cmdPrint_Click()

Dim strWhere As String

If Me.Dirty Then 'Save any edits.

Me.Dirty = False

End If

If Me.NewRecord Then 'Check there is a record to print

MsgBox "Select a record to print"

Else

strWhere = "[ID] = " & Me.[ID]

DoCmd.OpenReport "MyReport", acViewPreview, , strWhere

End If

End Sub



Notes: If your primary key is a Text type field (not a Number type field),
you need extra quotes: strWhere = "[ID] = """ & Me.[ID] & """"

If you want the report to print without preview, replace acViewPreview with
acViewNormal.



See also: http://allenbrowne.com/casu-15.html
 
Whenever I enter the record and then go to a report based on that
record the record does not show up in the report it is blank. Its
there but it appears that the table has not accepted the record when I
print. If I go back and then select another record and go back to the
last record it prints the selected record will usually work. How can I
get it to accept the last record keyed so I can print it?

Access does not save the record until you either go to the next
record, close the form, close the database or expressly tell it to
save the record.

In the command button click event that you are using to open the
report, write:

DoCmd.RunCommand acCmdSaveRecord
Docmd.OpenReport "ReportName", acViewPreview
 
Thanks that works great. So that means I have to add that to all the
code where I have buttons on the form and when I exit the form.
 
Thanks that works great. So that means I have to add that to all the
code where I have buttons on the form

Only if you intend to run a report or a query from that button.
and when I exit the form.

No. When you exit the form you are closing the form and access will
automatically save any new record data.
 
Don't know if this will work in every situation but I've had pretty good
luck with it so far.

Put this in the GotFocus event of the button.

Private Sub cmdPrint _GotFocus()
Refresh
End Sub
 
Back
Top