Results 1 to 8 of 8
  1. #1
    TinaCa is offline Advanced Beginner
    Windows Vista Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    87

    Open Report with Form

    I've used the code in various responses but it's not working for me. I keep getting all records not just the one I'm requesting.



    Dim strReportName As String
    Dim strCriteria As String

    strReportName = "rptCompanyHistory"
    strCriteria = "[CompanyAccountNo] =" & Me.CompanyAccountNo

    DoCmd.OpenReport strReportName, acViewPreview, strCriteria

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    is the criteria in the filter section? make sure it's in the "WHERE" clause section.

  3. #3
    TinaCa is offline Advanced Beginner
    Windows Vista Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    87

    my other report has this..

    Dim strReportName As String
    Dim AcctNo As Integer

    strReportName = "rptCompanyHistory"
    AcctNo = Me.CompanyAccountNo
    strCriteria = "[CompanyAccountNo] In (" & AcctNo & ")"

    DoCmd.OpenReport strReportName, acViewPreview, strCriteria

    Still not getting just the one I want. Also, the other reports don't have anything in the Filter section of the report. I use this query in other places so I do not want to hard code into the query.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    From VBA Help:
    expression.OpenReport(ReportName, View, FilterName, WhereCondition, WindowMode, OpenArgs)
    If [CompanyAccountNo] is a string instead of a number (which is what it should be) then you need to delimit with quotes:
    strReportName = "rptCompanyHistory"
    strCriteria = "[CompanyAccountNo] ='" & Me.CompanyAccountNo & "'"

    DoCmd.OpenReport strReportName, acViewPreview, , strCriteria
    ...and notice I moved to the WhereCondition argument.

  5. #5
    TinaCa is offline Advanced Beginner
    Windows Vista Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    87
    unfortunately, the companyaccountNo is a primary key so must be integer. do i need to use ' instead "

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    A Primary Key does not need to be an integer unless it is an AutoNumber in which case a number is just fine. Simply remove the single quotes.
    strCriteria = "[CompanyAccountNo] =" & Me.CompanyAccountNo

  7. #7
    TinaCa is offline Advanced Beginner
    Windows Vista Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    87
    I was missing a comma. Thanks folks

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Yep! Glad we could help.

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

Similar Threads

  1. Replies: 1
    Last Post: 08-01-2011, 04:17 PM
  2. Open Report or Form depending on condition
    By jheintz57 in forum Forms
    Replies: 5
    Last Post: 03-12-2010, 08:16 PM
  3. Replies: 2
    Last Post: 02-26-2010, 08:14 AM
  4. Replies: 3
    Last Post: 01-14-2010, 08:32 AM
  5. open report from a vb form
    By tracamonali in forum Reports
    Replies: 2
    Last Post: 08-10-2009, 01:55 PM

Tags for this Thread

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