Print Current Record in Report

BigNate

Board Regular
Joined
Dec 17, 2014
Messages
242
Hello Everyone,

I have an Access report and I want to only print a specific record. How is the best way to do this? I currrently have a button in the detail section, so this button shows for all records. Should I just use a code to print a single record and if so, can someone please tell me what the code would be for that button On_Click?

Thank you!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Thanks Joe.

I'm having an issue adapting your recommendation to fit my specific need. Specifically, I need to filter where the record has the corresponding radio button checked. In the case of my form, the radio button I am using is "YesOption". Do you by chance know how to alterr the code below so that it is correct and recognizes the radio button as being checked?

Private Sub OpenClaimReport_Click()
Dim strDocName As String
Dim strWhere As Variant
strDocName = "QCTClaimLogReport"
strWhere = [YesOption] = True
DoCmd.OpenReport strDocName, acPreview, , strWhere
End Sub

Thanks again!
 
Upvote 0
Try enclosing it in quotes, i.e.
Code:
[COLOR=#FF0000]strWhere = "[YesOption] = True"[/COLOR]
 
Upvote 0
Hmmmm, by doing that and then running the code, it then asked for me to enter the parameter value of "YesOption".

I tried changing the syntax slightly because I realized I probably wasn't properly calling the right form. Consequently, my code is now as follows but it is giving me an error of "expected end of statement"

Code:
Private Sub OpenClaimReport_Click()
Dim strDocName As String
Dim strWhere As Variant
    strDocName = "QCTClaimLogReport"
    strWhere = "Forms("QCTClaimLog").[YesOption] = True"
    DoCmd.OpenReport strDocName, acPreview, , strWhere
End Sub

Any ideas? :)
 
Upvote 0
So, the "YesOption" field is on your Form?
What field in your underlying table/query is this field bound to?
Does this bound field also appear on your report? If not, you may need to add it (you can always make it not visible if you do not wish to see it on the report).
 
Upvote 0
Correct, the "YesOption" field is on my form.

I just added this in my form. It isn't bound to another table or query. Does it need to be bound to the table that all data from the form and report are coming from?

I simply just want to use this as a way to filter the data. More specifically, I want my report to only show records with the YesOption radio button selected.

I appreciate your continuous help.

Thanks,
Nate
 
Upvote 0
Does it need to be bound to the table that all data from the form and report are coming from?
Yes! In order for it to be associated with a certain record, it needs to exist at the record level.
If it is only on the Form, it is "unbound", meaning it is not attached to anything.

If you have a "Primary Key" field being shown on your Form, just use that as your criteria instead.

Here are a few other links that may be helpful (one similar to the first, in more detail, and the other a little different):
https://support.microsoft.com/en-us/kb/209560
http://allenbrowne.com/casu-15.html
 
Upvote 0
But you typically don't bind radio buttons to fields. They're for taking actions based on user choices. The end of statement error is likely due to your use of double quotes. With respect to that, "Forms("QCTClaimLog").[YesOption] = True" should be "Forms('QCTClaimLog').[YesOption] = True", but that still does not look right. Your declaration of strDocName is not really necessary in such a small snippet of code like this, but it's what I'd expect to see if you're converting a macro to code. Also you are forcing Access to determine that your variant type is a string (text). Try this:

Private Sub OpenClaimReport_Click()
Dim strWhere As String
strWhere = "Forms!QCTClaimLog.YesOption = True"
DoCmd.OpenReport QCTClaimLogReport, acPreview, , strWhere
End Sub
I might still not have the where part correct, but it definitely is not right if you want to pass the value of a control instead of a hard-coded "True".
Make sure you are referencing the frameset around the radio buttons because it is what gets the option value, not the radio button itself.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,851
Messages
6,162,429
Members
451,765
Latest member
craigvan888

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top