Passing combobox value to a report

techexpressinc

Registered User.
Local time
Today, 09:00
Joined
Nov 26, 2008
Messages
185
How would I identify the value (field) in the drop-down of an unbound combo and get it passed to the query behind the report.

Attached are a couple of screen shots that show how it is going.
Screen shots
1) form in design mode
2) the vba code behind the button to create the report

Thanks for any help, as always.

Russ
 

Attachments

  • PassingValueOfComboBoxSelection2.JPG
    PassingValueOfComboBoxSelection2.JPG
    33.9 KB · Views: 347
  • PassingValueOfComboBoxSelection1.jpg
    PassingValueOfComboBoxSelection1.jpg
    96.1 KB · Views: 283
I'm not an expert by any means, but from what I can tell this should have worked. What is it doing or what error are you getting?
 
Re: Passing combobox value to a report - more info

Good question -

Attached two images:
1) Error message happening
2) The query that is behind the report, where I am attempting to pass the value in the drop-down to for a selection process.
 

Attachments

  • PassingValueOfComboBoxSelection4_query.JPG
    PassingValueOfComboBoxSelection4_query.JPG
    19.6 KB · Views: 255
  • PassingValueOfComboBoxSelection3_results.JPG
    PassingValueOfComboBoxSelection3_results.JPG
    18 KB · Views: 206
In the query you don't want it to refrence me.[associatelisting] you want [Forms]![associateform]![associatelisting]
 
right click in criteria and select build.
you can use that to point to it as well
 
You've put it in the wrong criteria (i.e. one criteria too many). It should go in the 4th parameter:
Code:
docmd.openreport "report name", acViewPreview[COLOR=Red], , [/COLOR]"criteria here"
Can you see the number of commas in mine in comparison to yours.
 
Getting closer - but no success yet

Thanks for the help, I think I need a little push more, I will post a Yippie when i get it to work.

One Problems at this time 11-23-11-730amEST -
1) Syntax error in query when adding the parameter:
[Forms]![associateform]![Associatelisting]

Russ
 
Are you talking about code or in the query? Can you show us what you are referring to.
 
getting a - syntax err

Attached is a screen shot of the error.
 

Attachments

  • PassingValueOfComboBoxSelection5_results.JPG
    PassingValueOfComboBoxSelection5_results.JPG
    46.1 KB · Views: 227
Can you see the extra bracket in the error? [

Plus, you should be using Me.ControlName if you are calling the OpenReport command from that form
 
still trying

The query behind the report is still failing to get the parameter.
I tried:
Me.Associatelisting
and
[Forms]![FrmSwitchBoard4SelectingPlanDoc]![Associatelisting]

However, with either I get the pop-up message
Enter Parameter Value and the variable. See attachments. Thx.


Here is the code behind the button now:
Code:
Private Sub Command4_Click()
On Error GoTo Err_Command24_Click
    Dim stDocName As String
    stDocName = "rpt_PIM_bjk_4_2006_1_person"
   DoCmd.OpenReport stDocName, acViewPreview, , "Me.Associatelisting"

' docmd.openreport "report name", acViewPreview, , "criteria here"
Exit_Command24_Click:
    Exit Sub
Err_Command24_Click:
    MsgBox Err.Description
    Resume Exit_Command24_Click
    
End Sub
 

Attachments

  • PassingValueOfComboBoxSelection6_results.JPG
    PassingValueOfComboBoxSelection6_results.JPG
    42.3 KB · Views: 182
  • PassingValueOfComboBoxSelection7_results.JPG
    PassingValueOfComboBoxSelection7_results.JPG
    14.9 KB · Views: 160
Remove the criteria that you have under PIandM and for the code use:
Code:
Private Sub Command4_Click()
On Error GoTo Err_Command24_Click

   DoCmd.OpenReport "rpt_PIM_bjk_4_2006_1_person", acViewPreview, , "PIandM = '" & Me.Associatelisting & "'"

Exit_Command24_Click:
    Exit Sub
Err_Command24_Click:
    MsgBox Err.Description
    Resume Exit_Command24_Click
    
End Sub
To be honest, remove all the criteria in your query until you get this working. Then you can put it back.
 

Users who are viewing this thread

Back
Top Bottom