Getting correct record from form onto report

G

Guest

I have a form and a report. I want the record that I am viewing on the form
to be the record that is displayed on the report.

I have found a similar question in the discussions and have tried that the
coding suggested but cannot get it to work. The coding in question is:-

Dim strDocName As String
Dim strWhere As String
strDocName = "rptSomeReport"
strWhere = "[RunID]=" & me!RunID
DoCmd.OpenReport strDocName, acPreview, , strWhere

The bit I don't understand is what to put in as RunID. Any help would be
appreciated.
 
G

Guest

Thanks Allen - that works fine.

--
Peter J Aldersley
BEDWORTH
England


Allen Browne said:
When Access asks for a parameter you don't expect, it means it does not
understand the name you intended.

If OF REF is the field name (with the space), then use exactly that in the
square brackets:
strWhere = "[of ref] = """ & Me.[OF REF] & """"

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

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

kayseypops said:
I've tried that and it comes back with a dialog box asking for a parameter
for of_ref.

Details are as follows:-

OF REF is the Primary Key which is a text field so I have put the extra ""
round as instructed in your notes. I notice that the first of_ref does
not
capitilise when moving to the next line when in VBA editor - could this be
something to do with the problem?

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 = "[of_ref] = """ & Me.[OF_REF] & """"

DoCmd.OpenReport "210 LETR - Showing Interest", acViewPreview, ,
strWhere
End If
End Sub

HELP!!!
--
Peter J Aldersley
BEDWORTH
England


Allen Browne said:
In that code, RunID represents the name of the primary key field of the
record in the form. Substitute you name of your autonumber field.

For an explanation of this approach, see:
Print the record in the form
at:
http://allenbrowne.com/casu-15.html

I have a form and a report. I want the record that I am viewing on the
form
to be the record that is displayed on the report.

I have found a similar question in the discussions and have tried that
the
coding suggested but cannot get it to work. The coding in question
is:-

Dim strDocName As String
Dim strWhere As String
strDocName = "rptSomeReport"
strWhere = "[RunID]=" & me!RunID
DoCmd.OpenReport strDocName, acPreview, , strWhere

The bit I don't understand is what to put in as RunID. Any help would
be
appreciated.
 

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