Current Record

G

Guest

I using the following code on a form which should take the current record and
send
it to a snapshot file via e-mail. What is happening is I get all the
records instead of
the current record. What I'm I doing wrong?

Thanks.


Private Sub Command29_Click()
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]
' LOL000913 Hobrand
If [Standard] = "EN 12021:1998" And [LOLID] = "LOL000913" Then GoTo
913
MsgBox [LOLID] & " has not been setup yet!"
GoTo 500
913 DoCmd.SendObject acSendReport, "HobrandEN12021913", acFormatSNP,
"abc123.net; testing123.net; (e-mail address removed)", , "(e-mail address removed)", "Your
Resutls", "Attached are your results for Report ID - " & strIdentify
500 End If
End Sub
 
D

Dirk Goldgar

rml said:
I using the following code on a form which should take the current
record and send
it to a snapshot file via e-mail. What is happening is I get all the
records instead of
the current record. What I'm I doing wrong?

Thanks.


Private Sub Command29_Click()
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]
' LOL000913 Hobrand
If [Standard] = "EN 12021:1998" And [LOLID] = "LOL000913"
Then GoTo 913
MsgBox [LOLID] & " has not been setup yet!"
GoTo 500
913 DoCmd.SendObject acSendReport, "HobrandEN12021913", acFormatSNP,
"abc123.net; testing123.net; (e-mail address removed)", , "(e-mail address removed)",
"Your Resutls", "Attached are your results for Report ID - " &
strIdentify 500 End If
End Sub

I see you're building what looks like a global report filter string,
gstrReportFilter, to identify the record to be reported. But what is
being done with this filter string? I'd expect to find code in your
report's Open event that applies this filter to the recordsource. Is
there such code?

If it's not being done there, the report's recordsource has to be set up
in such a way that the filter gets applied. Is it?

As a complete side issue, your use of "GoTo <line number> statements is
not good practice, and there's no real need for it, anyway. What's
wrong with a more normal If ... Then ... Else construction, like this:

If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
gstrReportFilter = "[ID] = " & Me.[ID]
strIdentify = [Identify]
' LOL000913 Hobrand
If [Standard] = "EN 12021:1998" And [LOLID] = "LOL000913" Then
DoCmd.SendObject acSendReport, _
"HobrandEN12021913", acFormatSNP,
"abc123.net; testing123.net; (e-mail address removed)", , _
"(e-mail address removed)", _
"Your Results", _
"Attached are your results for Report ID - " & _
strIdentify
Else
MsgBox [LOLID] & " has not been setup yet!"
End If
End If
 
A

Albert D. Kallal

No where in your code do you set a filter...
eg:


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

The above does not set a filter, but just assigns the expression "[ID] = " &
Me.[ID]
to a variable called ZooZoo

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

The above does not set a filter, but just assigns the expression "[ID] = " &
Me.[ID]
to a variable called Hello

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

The above does not set a filter, but just assings the expression "[ID] = " &
Me.[ID]
to a varabile called gstrReportFilter

DoCmd.SendObject acSendReport

The send object does not have a filter, but worse then that...you don't even
attempt to use the filter that you built anway!!

The soltion is that you need to open up the reprot first, then apply a
filter, and then use send object. In fact, better then setting a fitler, is
to use the reprots "where" caluse, since that allows you to restrict the
records to the report. You then use sendobject, which will use the CURRENTLY
open reprot...

Here is a working code snip

Dim strR As String

strR = "tblanswers"

DoCmd.OpenReport strR, acViewPreview, , "id = " & Me.ID
Reports(strR).Visible = False

DoCmd.SendObject acSendReport, _
strR, _
acFormatSNP, _
"(e-mail address removed)", , , _
"SUBJECT", , True

DoCmd.Close acReport, strR

Note how the reprot is then closed...do not forget to do this else next
time, the send object might send the wrong data to the wrong person....
 

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

Top