Results 1 to 10 of 10
  1. #1
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727

    syntax error

    All, using access 2010; I have a subform used in a form. I changed the query to filter information needed and now I am getting an error when I use the form. The query runs fine but not when the subform in on the form. Now the subform is all white. The error is: syntax error (missing operator) in query expression. Here’s my query:



    Code:
    SELECT tblMSRP.*, *
    FROM tblMSRP
    WHERE (((tblMSRP.ID)=DMin("ID","tblMSRP","gen_group='" & [gen_group] & "' AND rate=" & DMax("rate","tblMSRP","gen_group='" & [gen_group] & "'"))));

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Not sure if your query is a saved query, in VBA or a string in the sub-form record source.

    But it look like there is a missing double quote and closing parenthesis. It is easier to see if you remove the parenthesis Access adds...
    (I also added a couple of spaces and took out a double quote and the ampersand next to the "DMax" function)
    Code:
    SELECT tblMSRP.* 
    FROM tblMSRP 
    WHERE tblMSRP.ID = DMin("ID","tblMSRP","gen_group = '" & [gen_group] & "'") AND rate = DMax("rate","tblMSRP","gen_group = '" & [gen_group] & "'");
    After re-reading your post a few times, I'm going to say the SQL is the sub-form record source.

    Is [gen_group] a control on the main form? If yes, you would need to reference the control something like

    "Me.Parent.[gen_group]"

    The SQL would look like:
    Code:
    SELECT tblMSRP.* 
    FROM tblMSRP 
    WHERE tblMSRP.ID = DMin("ID","tblMSRP","gen_group='" & Me.Parent.[gen_group] & "'") AND rate = DMax("rate","tblMSRP","gen_group = '" & Me.Parent.[gen_group] & "'");

    Maybe I'm reading this wrong......

  3. #3
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    GM. thanks for replying. The recordsource for the subform has a query as the recordsource. gen_group is a control in the subform that is the child link to a master link control on the main form. thanks

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Do either of the above queries work?

    In the 2nd query, you would have to change the "Me.Parent.[gen_group]" to the name of the main form control (Master Link).

  5. #5
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    The first works but I get different results which are incorrect.

  6. #6
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    I don't understand because when I run the same query in another front end; I get the correct results. The subform shows up correct. Maybe this particular form is hosed up?

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Wouldn't hurt to delete the sub-form and re-create it.

  8. #8
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    I did just that and received the error: Syntax error (missing operator) in query expression ‘gen_group=” AND rate=’. When I click ok; i receive: This expression is typed incorrectly, or it is too complex to be evaluated. For ex. A numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to the variables.

  9. #9
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    OK, I found out I don't know enough about your dB.

    I tried to create a test dB w/ forms & queries.. didn't go as planned. I created 2 saved queries. Neither gave errors:
    Code:
    SELECT tblMSRP.*
    FROM tblMSRP
    WHERE (((tblMSRP.ID)=DMin("ID","tblMSRP","gen_group = '" & [gen_group] & "'")) AND ((tblMSRP.rate)=DMax("rate","tblMSRP","gen_group = '" & [gen_group] & "'")));

    Code:
    SELECT tblMSRP.* 
    FROM tblMSRP 
    WHERE tblMSRP.ID = DMin("ID","tblMSRP","gen_group='" & Forms!MainForm.[gen_group] & "'") AND rate = DMax("rate","tblMSRP","gen_group = '" & Forms!MainForm.Parent.[gen_group] & "'");
    If I took out the ID part of the where clause, I got one record, as I expected. I couldn't get the subform to return records if I had both criteria in the query.

    So, not knowing what your main form record source is and not knowing what any of the data looks like, I hit a wall.

    I don't understand how a record can have the ID (autonumber??) be the minimum AND (at the same time) the rate be max.


    Either one of the queries above will execute without errors. but that is as far as I could get.

  10. #10
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    The error message you are getting suggests that your dMax and/or DMin functions are returning nulls, which means the criteria used in them are not identifying any records, or that the values in the requested fields (ID and Rate) are all Null for a given value of [Gen_group]. Take a look at the table tblMSRP to see if the data is correct.

    HTH

    John

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

Similar Threads

  1. Replies: 3
    Last Post: 03-05-2013, 11:17 AM
  2. Compile Error: Syntax Error in DoCmd.RunSQL Statement
    By Evilferret in forum Programming
    Replies: 1
    Last Post: 08-27-2012, 12:32 PM
  3. Replies: 6
    Last Post: 05-30-2012, 12:32 PM
  4. Replies: 5
    Last Post: 03-27-2012, 01:40 PM
  5. Incomplete Syntax Clause (syntax error)
    By ajetrumpet in forum Programming
    Replies: 4
    Last Post: 09-11-2010, 10:47 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