Results 1 to 4 of 4
  1. #1
    dgmdvm is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2014
    Posts
    84

    OpenReport Syntax error

    In my database I have a form with a series of option buttons to modify the contents of a report. One of the options is based on a combo box BusTypeLst which lists a series of business types. The idea is that when the report opens the selected item in the combo box will become the "criteria" for the openreport command. I am getting a syntax error in my statement. The Access syntax error lists the portion of the statement 'totals.Business_type=' as the problem.



    This works (using one of the items in the combo box and inserting it into the statement):
    Code:
    Case Me.Option7.Value = True
       rptname = "Contacts List"
       prnttype = "Document"
       DoCmd.OpenReport rptname, acViewPreview, "Contact_list_query", "totals.Business_Type ='Advertising'", acWindowNormal, sortype 
       Set rpt = Reports(rptname)
       Set rpt.Printer = Application.Printers(Selprnt(prnttype))
       rpt.Printer.Orientation = acPRORLandscape
       DoCmd.Close acQuery, "Contact_List_query", acSaveNo
    This does not:
    Code:
    Case Me.Option7.Value = True
           rptname = "Contacts List"
           prnttype = "Document"
           DoCmd.OpenReport rptname, acViewPreview, "Contact_list_query", "totals.Business_Type = " & BusTypeLst.column(1), acWindowNormal, sortype 
           Set rpt = Reports(rptname)
           Set rpt.Printer = Application.Printers(Selprnt(prnttype))
           rpt.Printer.Orientation = acPRORLandscape
           DoCmd.Close acQuery, "Contact_List_query", acSaveNo
    The combobox has 2 columns, an ID field and the Business_type field.

    I've tried multiple syntax possibilities including this one: "totals.Business_Type = '" & BusTypeLst.column(1)"'" as well as setting the value of BusTypeLst.column(1) to a string variable.

    All my other option buttons on the form, which are based on simple strings, work fine and I can get the correct report generated.

    I will appreciate any help you can give me.

    Thanks

  2. #2
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You are missing an ampersand
    Code:
    "totals.Business_Type = '" & BusTypeLst.column(1) & "'"

    In the query "Contact_list_query", how many columns are named "Business_Type"? I would expect to see
    Code:
    DoCmd.OpenReport rptname, acViewPreview, "Contact_list_query", "Business_Type = '" & BusTypeLst.column(1) & "'", acWindowNormal, sortype

  3. #3
    dgmdvm is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2014
    Posts
    84
    Never mind. This works:
    Code:
    "totals.Business_Type ='" & Me.BusTypeLst.Column(1) & "'"
    I had to get up from the table and clear my head for a minute.

  4. #4
    dgmdvm is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2014
    Posts
    84
    In answer to your question contact_list _query has multiple alias' in it and "totals" is one of the the final tables in the query. I copied the expression from the SQL sheet figuring it would work ok.

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

Similar Threads

  1. Replies: 6
    Last Post: 11-28-2012, 03:43 PM
  2. Replies: 15
    Last Post: 07-26-2012, 02:06 PM
  3. Error: The OpenReport action was canceled
    By francisdm@state.gov in forum Reports
    Replies: 1
    Last Post: 12-14-2011, 01:45 PM
  4. Replies: 2
    Last Post: 10-13-2011, 09:14 AM
  5. error 3071 on OpenReport command
    By degras in forum Reports
    Replies: 5
    Last Post: 02-15-2011, 10:40 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