Ok. I will try all that. Since the database is very small and can be
recreated easy. Could I simply create a new db and follow all the
previous
steps? Creating a new db should not be corupt? Right?
Thanks
:
If:
- the code is present, and
- the On Open property is set to [Event Procedure], and
- the report was not already open, but
- the code is not runing, then
there is a corruption in the database.
A decompile will probably fix this kind of issue.
1. Uncheck the boxes under:
Tools | Options | General | Name AutoCorrect
Explanation of why:
http://allenbrowne.com/bug-03.html
2. Compact the database to get rid of this junk:
Tools | Database Utilities | Compact
3. Close Access. Make a backup copy of the file. Decompile the
database
by
entering something like this at the command prompt while Access is not
running. It is all one line, and include the quotes:
"c:\Program Files\Microsoft office\office\msaccess.exe" /decompile
"c:\MyPath\MyDatabase.mdb"
4. Open Access, and compact again.
5. Open a code window.
Choose References from the Tools menu.
Uncheck any references you do not need.
For a list of the ones you typically need in your version of Access,
see:
http://allenbrowne.com/ser-38.html
6. Still in the code window, choose Compile from the Debug menu.
Fix any errors, and repeat until it compiles okay.
At this point, you should have a database where the name-autocorrect
errors
are gone, the indexes are repaired, inconsistencies between the text-
and
compiled-versions of the code are fixed, and reference ambiguities are
resolved.
If it is still a problem, the next step would be to get Access to
rebuild
the database for you. Follow the steps for the first symptom in this
article:
Recovering from Corruption
at:
http://allenbrowne.com/ser-47.html
Yes, properties of report. Code is there. What do you think is the
problem
then?
Thanks.
:
Right: you have verified that the event is not firing.
Open the report in design view.
Open the Properties box (View menu.)
Make sure the Title bar of the Properties box reads Report, so you
are
looking at the properties of the Report, not those of a control.
Locate the On Open property (Events tab of Properties box.)
Set the property to:
[Event Procedure]
Click the Build button beside this. That should take you to the
code
we
are
talking about.
If the code is there, but does not run, we can talk about how to
solve
the
corruption in your database.
Report is and was closed. I applied the two lines of debugging
code
and
nothing. It does not stop. Still sends all records.
:
Make sure the report is closed when you run this. If it is
already
open,
the
filter will not be applied.
Let's add some debugging code to verify that a) the event is
firing,
and
b)
the right filter is being applied.
Immediately after the line:
Private Sub Report_Open...
add these two line:
Debug.Print gstrReportFilter
Stop
Save.
Now when click the button to create the email, Access should
open
the
code
window, and the Stop line should be hightlighted in yellow. If
that
does
not
happen, the event is not firing.
If it does stop, open the Immediate Window (Ctrl+G) and look at
the
filter
string that was printed out. What do you see? Does it make
sense?
Thanks for the reply. I added the line but still get all
records?
:
Open the report in design view.
You have set its On Open property to:
[Event Procedure]
so go to this property, and click the Build button (...) to
open
the
code
window to this event.
Immediately below the line:
Me.Filter = gstrReportFilter
add this line:
Me.FilterOn = True
Please post back if you are still stuck.
I followed your instructions:
Create Module1
Set properites of on open report
and here is the code on my form:
Private Sub Command29_Click()
Dim gstrReportFilter As String
'Dim strWhere As String
'Dim strIdentify 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
gstrReportFilter = "[ID] = " & Me.[ID]
'strIdentify = [Identify]
DoCmd.SendObject acSendReport, "SprintSafetyD",
acFormatSNP,
"(e-mail address removed)", , , "Please Find Stats", strIdentify
End If
End Sub
It still sends all records? What do you think I'm doing
wrong?
Thanks for the help.
:
Unlike OpenReport, there is no place to apply the
WhereCondition
when
you
SendObject. You can work around that by creating a public
string
to
hold
the
filter value, and applying it in the Open event of the
report.
1. Choose the Modules tab of the Database window.
Click New. Access opens a new module.
In the General Declarations section (just below the
Option
statements),
enter:
Public gstrReportFilter As String
Save the module with a name such as Module1.
2. Open your report in design view.
Open the Properties box (View menu.)
Set the report's On Open property (Event tab of properties
box)
to:
[Event Procedure]
Click the Build button (...) beside this.
Access opens the code window.
Enter the code so the event procedure looks like this:
Private Sub Report_Open(Cancel As Integer)
If gstrReportFilter <> vbNullString Then
Me.Filter = gstrReportFilter
gstrReportFilter = vbNullString
End If
End Sub
3. Change your existing code so that it sets the public
string
instead
of
strWhere:
If Me.NewRecord Then
MsgBox "Select a record to print"
Else
gstrReportFilter = "[ID] = " & Me.[ID]
DoCmd.SendObject acSendReport, "SprintSafetyD", _
acFormatSNP, "(e-mail address removed)", , , "Please
Find
Stats"
End If
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
I'm trying to send the current record to a snapshot file
with
the
following
code. It works fine except it sends all records. Can
anyone
show
me
what
I'm doing wrong?
Thanks.
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.SendObject acSendReport, "SprintSafetyD",
acFormatSNP,
"(e-mail address removed)", , , "Please Find Stats"
End If