Results 1 to 5 of 5
  1. #1
    craig1988 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2014
    Posts
    82

    Opening a report using criteria from a form

    Hi All



    Just a head scratcher that I cant figure out...

    I have a form "frmA" with a data source of "tblA". It has a combo box "cboA" which looks up values from "tblB". Beside the combo box I have a button "btnA". What I would like to do is open a report "rptA" with the criteria being the value of the combo box.


    DoCmd.OpenReport rptA, acViewReport, , ???

    Please help

    Thanks

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I will typically do something like the following ...
    Code:
    Dim strWhere As String
    strWhere = "[FieldName] =" & Me.ControlNameOfNumberType
    DoCmd.OpenReport "rptA", , , strWhere

  3. #3
    craig1988 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2014
    Posts
    82
    Yes... Thank you!!

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    OK, glad you were able to work through it. Moving forward, pay close attention to data types. When comparing values, it is important to compare variables of similar data types.

    In other words, text is not a number.

  5. #5
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,463
    You could also put the criteria directly in the RecordSource of the Report, then when you open the report it already is looking for those criteria. In the RecordSource query of the report, right click in the Criteria row for that field and use Build, double click on forms, click on your form and then find the combo field from the list and double click. It gets you the right syntax.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Opening a report from a form command
    By undee69 in forum Reports
    Replies: 4
    Last Post: 01-13-2013, 08:57 AM
  2. Opening a report with search criteria through a combo box
    By very_much_a_beginner in forum Reports
    Replies: 1
    Last Post: 07-16-2012, 01:30 PM
  3. Replies: 1
    Last Post: 01-10-2012, 03:44 AM
  4. Link Criteria no working when opening new form
    By ETCallHome in forum Forms
    Replies: 1
    Last Post: 06-17-2011, 05:26 AM
  5. Opening Report From Form
    By injanib in forum Forms
    Replies: 4
    Last Post: 02-08-2011, 08:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums