Open a current record report from a form?

R

Rose

Is there away to open a report from a form to show only that students ID.

For example, I have a form in which I can input all my students’
information, grades, attendance, etc. I want to create a macro or something
in which I can tell a report to only show me the current student’s record.
This is based on StudentID.

Thanks
 
F

fredg

Is there away to open a report from a form to show only that students ID.

For example, I have a form in which I can input all my students¢
information, grades, attendance, etc. I want to create a macro or something
in which I can tell a report to only show me the current student¢s record.
This is based on StudentID.

Thanks

Your table should have a unique prime key field.
In my example it is named [StudentID].

Add a command button to the form.
On the command button's property sheet click on the Event tab.
On the Click event line, write
[Event Procedure]

Then click on the little button with 3 dots that will appear on that
line.
When the code window opens, the cursor will be flashing between 2
already existing lines of code.
Between those 2 lines write:

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "ReportName", acViewPreview, , "[StudentID] = " &
Me![StudentID]

The above assumes a [StudentID] field that is a Number Datatype.

If, however, [StudentID] is Text Datatype, then use:

DoCmd.OpenReport "ReportName", acViewPreview, ,"[StudentID] = '" &
Me![StudentID] & "'"

For clarity, the above single and double quotes are..
"[StudentID] = ' " & [StudentID] & " ' "

See VBA Help files for:
Where Clause + Restrict data to a subset of records'
 
Top