Results 1 to 11 of 11
  1. #1
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jun 2016
    Posts
    310

    Syntax error in opening a report

    Hi to All,
    I have the folowing line of code:
    Code:
    DoCmd.OpenReport "rptMemberBorrowedBooks", view:=acViewPreview, Wherecondition:=mstrWHERE
    where mstrWHERE is:
    Code:
    mstrWHERE = "fkMemberID = " & Me.cboSelectedPerson & varReturned & varDates
    varReturned: Is a criteria for a field if it is Null or Not Null
    varDates: Is an ORDER BY a fieldName (one of three fields)

    Running the command button to print the report gives the following error message:
    Error 3075: Syntax error (missing operator) in query expression 'fkMemberId = 42 AND [DateReturned] is not null Order by DueDate'



    Any ideas please?
    Khalil

  2. #2
    xps35's Avatar
    xps35 is online now Competent Performer
    Windows 10 Office 365
    Join Date
    Jun 2022
    Location
    Schiedam, NL
    Posts
    299
    There order by should not be there.
    Groeten,

    Peter

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,930
    No benefit in using the order by, the report will ignore it - you need to set the order in the report

    Suggest show the report recordsource

  4. #4
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jun 2016
    Posts
    310
    Hi,
    Thank you both.
    My mstrWHERE is like this: (removed the Order by)
    Code:
    mstrWHERE = "fkMemberID = " & Me.cboSelectedPerson & varReturned & varDates
    I can see the report in the Print View.
    How cna I set the order from the report to be based on he value of: varDates?

    Khalil

  5. #5
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,930
    Presume removing the order by solved your syntax error

    it is set in the report properties and/or the group/sort/totals section at the bottom of the report design view

  6. #6
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jun 2016
    Posts
    310
    Hi,
    My issue is that my sorting is based on a dateField selected by an option group value (fraDates) on a form; The fraDates has three radio buttons: Date Borrowed, Date Due and Date Returned (Three different fields).
    The user will choose one of the three date fields to sort.

    How can I tell the report to use the selected date field to be used for sorting when opening the report?
    Is it possible to do this using the On Load or On Open Event procedure of the report? How can it be done?

    Khalil

  7. #7
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    You could pass the sort order in using the OpenArgs option and process it in the reports open event?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  8. #8
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jun 2016
    Posts
    310
    Hi,
    Thank you for the suggestion of using OpenArgs. I lake the experience of using the OpenArgs option; I did some reading about it.
    The form has a command button to open the report;

    Step 1:
    I should define the string that will be used as the OpenArgs which is fraDates on the form.
    What should I write here?

    Step 2:
    I should have some lines on the report Open event to PASS the OpenArgs Value.
    Code:
    Dim strArgs As Integer
        strArgs = FormName!OpenArgs
    I not certain if I have the correct lines.

    Step 3:
    Use the command to open the report:
    Code:
    DoCmd.OpenReport "rptMemberBorrowedBooks", acViewPreview, , mstrWHERE1, , OpenArgs

    Khalil

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    Dim strArgs As Integer
    Seriously, you have a variable called strArgs and define it is Integer ?

    Way to go to confuse people. including yourself.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jun 2016
    Posts
    310
    Sorry,
    It should be defined as a string

  11. #11
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    Quote Originally Posted by Khalil Handal View Post
    Hi,
    Thank you for the suggestion of using OpenArgs. I lake the experience of using the OpenArgs option; I did some reading about it.
    The form has a command button to open the report;

    Step 1:
    I should define the string that will be used as the OpenArgs which is fraDates on the form.
    What should I write here?

    Step 2:
    I should have some lines on the report Open event to PASS the OpenArgs Value.
    Code:
    Dim strArgs As Integer
        strArgs = FormName!OpenArgs
    I not certain if I have the correct lines.

    Step 3:
    Use the command to open the report:
    Code:
    DoCmd.OpenReport "rptMemberBorrowedBooks", acViewPreview, , mstrWHERE1, , OpenArgs

    Khalil
    https://learn.microsoft.com/en-us/of...form-or-report
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 15
    Last Post: 03-01-2021, 12:07 PM
  2. Replies: 5
    Last Post: 09-16-2018, 01:18 PM
  3. Convert SQL Server Syntax To Access Query Syntax
    By chalupabatman in forum Queries
    Replies: 1
    Last Post: 10-18-2017, 08:53 PM
  4. Replies: 3
    Last Post: 01-23-2014, 07:49 AM
  5. Incomplete Syntax Clause (syntax error)
    By ajetrumpet in forum Programming
    Replies: 4
    Last Post: 09-11-2010, 10:47 AM

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