Access- Parameter query data from Combo box?

  linden 23:05 12 Mar 05

I have a database that prints a report using a parameter query that asks for the surname of a person. ( surname is a field in a table )
This is OK.
But it would be better to have a drop down list of the surnames. This I can manage with a combo box on a form. I can make a command button on the form that prints the report. It asks for the surname. How can I tell the command button to use the chosen name from the combo list. ( or tell the combo list to send its current view to the command button ! )
Hope someone can help?


  AccessMoron 08:46 13 Mar 05

Use the command button to print out the report,
base the report on a stright query (no parameters)

When you open the report with the command button, uhse a where statement.

DoCmd.OpenReport "", acViewNormal, , "Surname = ' " & comboValue & "'"

  linden 21:29 13 Mar 05

Thank you to AccessMoron for a quick reply. Much closer now but I get "compile error - syntax error" when I click the button. The debugger opens with the code below. Being a raw beginner with code I expect I have a stupid mistake in here

My qury ( qryDifference ) has no parameter.
The report ( rptDifferenceSingle ) opens OK with all records showing.
The combo box ( combo5 ) shows all the surnames.
The command button ( PreviewDiff has the following event code on click
Private Sub PreviewDiff_Click()
On Error GoTo Err_PreviewDiff_Click

Dim stDocName As String

stDocName = "rptDifferenceSingle"
DoCmd.OpenReport strDocName, acViewNormal, , "Surname='"
& combo5Value & ""
Exit Sub


Problem seems to be in the line beginning & combo

Should there be somthing in the double spech marks at the end of thatline?

Hope you can suggest something

Thank you


  AccessMoron 23:54 13 Mar 05

ok try this
stDocName = "rptDifferenceSingle" DoCmd.OpenReport strDocName, acViewNormal, , "Surname=[single quote][double quotes] & combo5Value & [doulbele quote][single quote] [double quote] Exit_PreviewDiff_Click: Exit Sub

  linden 07:33 14 Mar 05

Thanks to AccessMoron
I will try that later today.

  linden 15:39 14 Mar 05

To AccessMoron
Almost there I hope. Got error msg about Report name but noticed slight mismatch above ( strDocName cf stDocName )

Now the button produces a print of one record, but no data ie no surname or details. Format is correct. One page only is as it should be.

Two things : can I have preview instead of an actual print ( should have said that earlier)

Next : should the combo have anything in its event procedure ( on focus perhaps ) mine has no event procedure.

I appreciate your time and trouble


  AccessMoron 20:05 14 Mar 05

1. Change acViewNormal to acPreview
2. No you do not need anything in the combo events

  linden 20:33 14 Mar 05

Now I get a preview instead of a print. Thanks.

But the page has no data on. The spaces and boxes are exactly as they should be but empty. The name in the combo box has not been used.

My last message - when I said "one page only is as it should be" was unclear - I meant it showed one blank page - not lots of blank pages. ( without the parameter in the query the report alone would produce many pages - all filled with data from all the surnames )
Hope that has not muddied the water even more!!

  AccessMoron 20:39 14 Mar 05

post me the database

This thread is now locked and can not be replied to.

Sniper Elite 4 review: Headshotting Nazis has never felt so good

1995-2015: How technology has changed the world in 20 years

The Best Design, Illustration, Animation and VFX Awards of 2017

WWDC 2017 dates: How to get WWDC 2017 tickets, when is WWDC 2017 and more details announced