Creating Reports for single records

Chris Hump

Access VBA Amateur
Local time
Today, 08:11
Joined
Nov 16, 2009
Messages
10
I have a form in which students enter their student ID codes then make their choices of modules with each module being a field which they have to select using a tick box accordingly.

Once they have made their choices I want to be able to print off a report of just that one record that displays only the options that they have checked the tick box for.

What is the best way to set about doing this?
 
Last edited:
If MsgBox("Do you wish to print your choices?", vbYesNo, "Print?") = vbYes Then
********
DoCmd.Save
DoCmd.Close
Else
DoCmd.Save
DoCmd.Close
End If


This is the code I currently have, I've set up a report called options that will need to be printed to the current record if 'yes' is selected. Does anyone know what code I should put in place of the *'s in order to do this?
 
DoCmd.Save

Just so you are aware, the DoCmd.Save has nothing to do with Records. It has to do with Design Changes to the form or report. If you are trying to save a record you can do it with either:

If Me.Dirty Then Me.Dirty = False ' which saves only if something is needing to be saved

or

DoCmd.RunCommand acCmdSaveRecord

which will attempt a save regardless of whether something needs to be saved or not.
 
ah i should have said. that code is on a form that saves the changes to the entry, then as they select this i want the yes/no to appear and if they select yes i want to print a report for the record selected in the form.


edit: just read what you've put again and realised i misunderstood. will change that now re: saving records.
 
Last edited:
ah i should have said. that code is on a form that saves the changes to the entry,
Then you don't use DoCmd.Save for that. Use the other code.

then as they select this i want the yes/no to appear and iff they select yes i want to print a report for the record selected in the form.
Did the link that RuralGuy give not give you enough?
 
Then you don't use DoCmd.Save for that. Use the other code.


Did the link that RuralGuy give not give you enough?

strWhere = "[RunID]=" & me!RunID

In this part of the code do I need to substitute something in place of RunID?
 
strWhere = "[RunID]=" & me!RunID

In this part of the code do I need to substitute something in place of RunID?

What you do is use

"[WhateverFieldIsThePrimaryKeyInReportRecordset]=" & Me!YourKeyFieldOnTheFormThatWillMatchTheReportKey

Replacing each part with the appropriate field name.
 
If MsgBox("Do you wish to print your choices?", vbYesNo, "Print?") = vbYes Then

strDocName = "Options"
strWhere = "Student_ID=" & Me!Student_ID
DoCmd.OpenReport strDocName, acPreview, , strWhere
DoCmd.Close
Else

DoCmd.Close
End If



running this returns me a runtime error 2465 and it has a problem with the bit after Me!


Could this be because at this point the form hasnt saved the record to the table?
 
If MsgBox("Do you wish to print your choices?", vbYesNo, "Print?") = vbYes Then

strDocName = "Options"
strWhere = "Student_ID=" & Me!Student_ID
DoCmd.OpenReport strDocName, acPreview, , strWhere
DoCmd.Close
Else

DoCmd.Close
End If



running this returns me a runtime error 2465 and it has a problem with the bit after Me!


Could this be because at this point the form hasnt saved the record to the table?

1. Is Student_ID (the EXACT spelling) a field in BOTH the report AND the form?

2. Try changing your code to include the line:

If Me.Dirty Then Me.Dirty = False

just before the

strDocName = "Options"

line.
 
I cant seem to get this to work.

Would it be any easier to output the selection to word/excel and print them from there? Or run a query that returns the student id and the options they have selected?
 
If the StudentID is a string then you will need to make a change:
"Student_ID='" & Me!Student_ID & "'"
 
I've looked through the watch thing in the debug menu and have found something that says : Text : <You can't reference a property or method for a control unless the control has the focus.> : String : Form_Option Form.Command30_Click

will i have to focus back to student ID before I run the report?
 
You do not need to reference the .Text property, just the .Value property which is the default and need not be specified. Try using "." instead of the "!" so the intellisense works.
strWhere = "Student_ID='" & Me.Student_ID & "'"
You should get a list of controls when you enter the "." after the Me.
 
View attachment SelectOptions.mdb

I can't seem to get it to work. I've attached a copy of my database if you want to look and see what I've done wrong.

I am trying to get it so that when you select save choices on the options form you are given the option to print the choices you have just made in the options report.

If anyone could work out a way of doing this I would be eternally grateful, I can't seem to move on to make other improvements with this outstanding and its ever so frustrating!

I've deleted the code that I was using as I was worried I would end up breaking something else. But its all written above anyway.
 
This is great thanks, the only problem now is I can't seem to add new records to the form.
 
You are going to need to use the NotInList event of the ComboBox.
 

Users who are viewing this thread

Back
Top Bottom