Results 1 to 7 of 7

Thread: [RESOLVED] syntax error "select max(fields) from table"

  1. #1

    Thread Starter
    Fanatic Member ksuwanto8ksd's Avatar
    Join Date
    Apr 2005
    Posts
    636

    Resolved [RESOLVED] syntax error "select max(fields) from table"

    I have a table "ORDER" database access 2k its structure is:

    orderid = autonumber
    orderdate= date
    supplierid=text
    suppliername=text

    in my form have a textbox name "txtnota" and a command button click event code:
    VB Code:
    1. Private Sub command1_Click()
    2.     call RsTmp
    3. end sub
    4.  
    5.  
    6. Sub RsTmp()
    7. Dim RsTmp As ADODB.Recordset
    8.  
    9. msql = "select * from order " & _
    10.        "where orderid in (select max(orderid) from order)"
    11. [b]Set RsTmp = con_cashReg.Execute(msql) 'error here[/b]
    12. If Not (RsTmp Is Nothing) Then
    13.    If (Not RsTmp.BOF) And (Not RsTmp.EOF) Then
    14.       txtnota.Text = RsTmp.Fields("orderid").Value + 1
    15.    Else
    16.    txtnota.Text = 1
    17.    End If
    18.    RsTmp.Close
    19. End If
    20. End Sub

    the run time error is:
    "syntax error in FROM clause"
    Im regard it can get max number from "OrderId" field and add 1 to it
    i dont know what wrong with this, If any one can help me is very much appreciated. thanks in advance

    best regard

  2. #2

    Thread Starter
    Fanatic Member ksuwanto8ksd's Avatar
    Join Date
    Apr 2005
    Posts
    636

    Re: syntax error "select max(fields) from table"

    Additional information;

    when I change table to this structure then working fine: (Orderdetail)

    OrderId=number
    ProductId=text
    ProductName=text
    Unit=text

    I just simply change the Order to Orderdetail

    If any one can help thanks

    best regards,

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: syntax error "select max(fields) from table"

    The problem is that Order is a reserved word (from "Order By"), so should not be used as a table or field name, as it leads to the database engine getting confused.

    What you should do is re-name the table. An alternative is to put square brackets around the name (eg: "from [order]"), but this will not work in all situations.

  4. #4

    Thread Starter
    Fanatic Member ksuwanto8ksd's Avatar
    Join Date
    Apr 2005
    Posts
    636

    Re: syntax error "select max(fields) from table"

    Hi Si the geek

    thanks, Your quick replay is appreciated
    good rate

  5. #5

    Thread Starter
    Fanatic Member ksuwanto8ksd's Avatar
    Join Date
    Apr 2005
    Posts
    636

    Re: syntax error "select max(fields) from table"

    One more turn,

    hi ,.si the geek, can u tell me "[]" in what situation doesnt work?
    thanks

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: syntax error "select max(fields) from table"

    I don't know about situations where it wouldn't work, only situations were it is required (like using reserved words).

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: syntax error "select max(fields) from table"

    To be completely honest, I cant remember!

    All I know is that there have been cases on the forums where it doesn't work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width