Printinmg of first record

  • Thread starter Thread starter Alex H
  • Start date Start date
A

Alex H

Hi

I have a mainform with a subform. On occassions I need to print a report
based on the current record. I have a field called [RecordId ](which is an
autonumber and is visible on the main form. The control Name is CID.


I am using the following code
Dim strDocName As String
Dim strCriteria As String
Dim Id As String

strDocName = "RptEnableLicenceNotification"
strCriteria = "[RecordId] = '" & Me![CID] & "'"
Id = [RecordId]
MsgBox Id
DoCmd.OpenReport strDocName, acViewPreview, , strCriteria

I am using the message box to ensure that I am getting the right record,
which I am, but then literally nothing happens.
If I remove the strCriteria line, the report is displayed with the correct
data, the only problem is that it displays all of the records in the table,
not just the first one, and if I forget to select to print just record
number 1 from printer options, i use another tree!!

Any help much appreciated

XXXX
 
Forgot to say that I had also used
strCriteria = "[RecordId] = '" & Me![RecordId] & "'"
first, and changed the code to the control name to see if that worked.

Thanks

Alex
 
I think the problem is that the RecordId field is a numeric
field and you're using quotes around its value, which would
only be appropriate if it is a Text field.

strCriteria = "[RecordId] = " & Me![CID]
--
Marsh
MVP [MS Access]




Alex said:
Forgot to say that I had also used
strCriteria = "[RecordId] = '" & Me![RecordId] & "'"
first, and changed the code to the control name to see if that worked.

"Alex H" wrote
I have a mainform with a subform. On occassions I need to print a report
based on the current record. I have a field called [RecordId ](which is an
autonumber and is visible on the main form. The control Name is CID.


I am using the following code
Dim strDocName As String
Dim strCriteria As String
Dim Id As String

strDocName = "RptEnableLicenceNotification"
strCriteria = "[RecordId] = '" & Me![CID] & "'"
Id = [RecordId]
MsgBox Id
DoCmd.OpenReport strDocName, acViewPreview, , strCriteria

I am using the message box to ensure that I am getting the right record,
which I am, but then literally nothing happens.
If I remove the strCriteria line, the report is displayed with the correct
data, the only problem is that it displays all of the records in the
table,
 
What is the name of the id field in that table used for the report?

If you can go:

Id = [RecordId]

Then, it seems to me that your field you should be using is ReocrdId, and
NOT cid?

strCriteria = "[RecordId] = '" & me!RecodId & "'"

As mentioned, if RecordId is in fact a number field, then you use:

strCriteria = "[RecordId] = " & me!RecordId

You also do NOT need to actually put, or place the RecordId field on the
form. As long as the underlying reocrdset for the form has the field, you
can use/ref it.

Further, if your code that checks the id should use:
Id = me!CID
MsgBox Id

I mean, if you are testing for a [RecorId] field = to the "some" value you
are passing, would not want to test/show the actual value you are passing?
You are passing CID, but showing for your test code [RecordId]. There is
some confusing here!

In your case, you are sending the value of ME!CID to the where clause, but
in you test code you display [reocrdId]. Why would you do that? This just
shows me that you do not realize that the "where" clause you are passing to
the openrpeot is simply a sql where that runs on the "reports" table.

"[RecordId] = 123"

or

"[LastName] = 'Kallal'"

That above condition is based on the field name in the report, and has
NOTHING to do with the field names you are using in your form. So, that
[ReocrdId] field, or [LastName] field is a valid field in the reports
reocrdsouce...and not your form.
 
Thanks guys

Of course was looking at it too long - was a numeric field so didn't need
the quotes

Mind must be going :)

Alex
 
Back
Top