Send current record as snapshot

R

rml

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
 
A

Allen Browne

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
 
R

rml

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.


Allen Browne said:
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.

rml said:
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
 
A

Allen Browne

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.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

rml said:
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.


Allen Browne said:
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.

rml said:
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
 
R

rml

Thanks for the reply. I added the line but still get all records?


Allen Browne said:
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.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

rml said:
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.


Allen Browne said:
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
 
A

Allen Browne

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?

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

rml said:
Thanks for the reply. I added the line but still get all records?


Allen Browne said:
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.

rml said:
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
 
R

rml

Report is and was closed. I applied the two lines of debugging code and
nothing. It does not stop. Still sends all records.



Allen Browne said:
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?

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

rml said:
Thanks for the reply. I added the line but still get all records?


Allen Browne said:
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
 
A

Allen Browne

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.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

rml said:
Report is and was closed. I applied the two lines of debugging code and
nothing. It does not stop. Still sends all records.



Allen Browne said:
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?

rml said:
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
 
R

rml

Yes, properties of report. Code is there. What do you think is the problem
then?

Thanks.

Allen Browne said:
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.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

rml said:
Report is and was closed. I applied the two lines of debugging code and
nothing. It does not stop. Still sends all records.



Allen Browne said:
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
 
A

Allen Browne

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


--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

rml said:
Yes, properties of report. Code is there. What do you think is the
problem
then?

Thanks.

Allen Browne said:
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.

rml said:
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
 
R

rml

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

Allen Browne said:
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


--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

rml said:
Yes, properties of report. Code is there. What do you think is the
problem
then?

Thanks.

Allen Browne said:
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
 
A

Allen Browne

If you want to recreate it, do perform the first 4 steps first. Otherwise
you may simply import the corruption.

Then when you create the new database, be sure to disable Name AutoCorrect
*before* import. After import, pick up at step 5 so you have the minimal
references in the new database, and confirm that everything compiles okay.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

rml said:
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

Allen Browne said:
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


rml said:
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
 
R

rml

Ok. I did everything but still get all records. One thing I did find out is
if you simply open the report without the code from the form, it does stop at
the "stop" line but does not show gstrReportFilter. If it was working I
would see that variable? I went over everything multiple times to make sure
I have everything correct and It all looks good. Anything else we can try?
Are we missing something?

Thanks.

Allen Browne said:
If you want to recreate it, do perform the first 4 steps first. Otherwise
you may simply import the corruption.

Then when you create the new database, be sure to disable Name AutoCorrect
*before* import. After import, pick up at step 5 so you have the minimal
references in the new database, and confirm that everything compiles okay.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

rml said:
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

Allen Browne said:
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
 
R

rml

I GOT IT! I was looking over the code very carefully and on the command
button of my form I hade the following:

Dim gstrReportFilter As String

I removed this line and it works perfect. I guess having that line it
canceled out the public variable in the module1. Right? Anyway, I reallly
appreciate all your help and time.

I do have on last question for you. In the folowing code, it send a snp
file to e-mail with the default name of the e-mail of the report name. For
instance; aaa.snp

Can this be changed? I would like the snp file name to be strIdentify.snp
strIdentify is a field value of an unique number. Not sure if this can be
done or of the syntax.

DoCmd.SendObject acSendReport, "aaa", acFormatSNP, "(e-mail address removed)", , ,
"abc123", "Results - " & strIdentify

Thanks again.

Allen Browne said:
If you want to recreate it, do perform the first 4 steps first. Otherwise
you may simply import the corruption.

Then when you create the new database, be sure to disable Name AutoCorrect
*before* import. After import, pick up at step 5 so you have the minimal
references in the new database, and confirm that everything compiles okay.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

rml said:
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

Allen Browne said:
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
 
A

Allen Browne

Great: you have it working.

You want to rename the attachment? Without testing, I cannot think of an
easy way to do that, short of renaming the report before opening it.

If that's really important, and you can be certain that the user's default
mail program is Outlook, you could eport the file, rename it, and
programmatically create an email (using an Outlook object), and attach the
file. I suspect that has more disadvantages than the benefit it would give.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

rml said:
I GOT IT! I was looking over the code very carefully and on the command
button of my form I hade the following:

Dim gstrReportFilter As String

I removed this line and it works perfect. I guess having that line it
canceled out the public variable in the module1. Right? Anyway, I
reallly
appreciate all your help and time.

I do have on last question for you. In the folowing code, it send a snp
file to e-mail with the default name of the e-mail of the report name.
For
instance; aaa.snp

Can this be changed? I would like the snp file name to be strIdentify.snp
strIdentify is a field value of an unique number. Not sure if this can
be
done or of the syntax.

DoCmd.SendObject acSendReport, "aaa", acFormatSNP, "(e-mail address removed)", , ,
"abc123", "Results - " & strIdentify

Thanks again.

Allen Browne said:
If you want to recreate it, do perform the first 4 steps first. Otherwise
you may simply import the corruption.

Then when you create the new database, be sure to disable Name
AutoCorrect
*before* import. After import, pick up at step 5 so you have the minimal
references in the new database, and confirm that everything compiles
okay.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

rml said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Dynamic Naming of Form Button 3
Print Current Record 9
Open Form 17
Error on command button 2
Printing current record of a form 2
Current Record 2
Concatenate field as PK 9
print record in form. . .not working 2

Top