Access- Parameter query data from Combo box?

  linden 23:05 12 Mar 2005
Locked

Help!
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?

Linden

  AccessMoron 08:46 13 Mar 2005

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 2005

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_PreviewDiff_Click:
Exit Sub

Err_PreviewDiff_Click:
---------------

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

Linden

  AccessMoron 23:54 13 Mar 2005

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 2005

Thanks to AccessMoron
I will try that later today.
Linden

  linden 15:39 14 Mar 2005

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

Linden

  AccessMoron 20:05 14 Mar 2005

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

  linden 20:33 14 Mar 2005

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 2005

post me the database

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

Elsewhere on IDG sites

iPhone X review

Political cartoons in 2017: Chris Riddell, Rebecca Hendin and Dave Brown on what it’s like to…

The best iPhone for 2017

Tennis : comment regarder la finale de la Coupe Davis 2017 ?