Results 1 to 8 of 8

Thread: SQL Problem with using UPDATE query in Access

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Location
    hongkong
    Posts
    251
    Oh, Dear Friends,

    I have a problem in using DoCmd.RunSQL again. This time I wish to update the old data in one table from another newly added table that contains fresh data.

    My code is:
    sSQL = "UPDATE Stock SET " & _
    "Name=" & MyTableName & ".Name " & _
    "FROM " & MyTableName & " " & _
    "WHERE Stock.Ticker=" & MyTableName & ".Ticker"

    ' Run the SQL on the Access mdb from my program
    accApp.DoCmd.RunSQL sSQL


    My SQL statement is (when debug.print):

    UPDATE Stock SET Name=TempTable.Name FROM TempTable WHERE Stock.Ticker=TempTable.Ticker

    What's wrong with it? Can u help me to point this out? Thanks a lot.

  2. #2
    Addicted Member
    Join Date
    Feb 2001
    Location
    Chennai, India
    Posts
    219
    I wont abit more explanation. According to the way I see the question, u want to update STOCK table with the contents of the TempTable.
    If my understanding is correct, u can't directly use another table's values. What u can do is store the value of the other table in a variable and then use that variable for updation.
    Any probs, inform us

    Cheers
    Parasuraman
    Om Nama Sivaya!!!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Location
    hongkong
    Posts
    251

    But ... Syntax Error It says

    Originally posted by Parasu Raman
    I wont abit more explanation. According to the way I see the question, u want to update STOCK table with the contents of the TempTable.
    If my understanding is correct, u can't directly use another table's values. What u can do is store the value of the other table in a variable and then use that variable for updation.
    Any probs, inform us

    Cheers
    Parasuraman
    Dear Parasuraman,
    Thanks for oyur kindly reply. But I have forgot to say when I run this SQL, the VB prompts an error message:

    Sysntax error(MIssing Operator) in query expression 'TempTable.Name FROM TempTable'

    So is it the ACCESS can't recognize the syntax of Table.Field? Can you write the correct SQL for me if according to yrour mentioned method?

  4. #4
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    Easy way to get the correct SQL string for Access: create the query in the QBE grid, look at the SQL it creates, copy it into your VB project, substitute in any variables as required and you are done.

  5. #5
    Addicted Member
    Join Date
    Feb 2001
    Location
    Chennai, India
    Posts
    219
    JamesM,
    I havent heard of the QBE Grid. Can u pls show light on it and I could'nt find it in the components list.
    Parasuraman
    Om Nama Sivaya!!!

  6. #6
    Addicted Member
    Join Date
    Feb 2001
    Location
    Chennai, India
    Posts
    219
    Cantene,
    here is a short form code. Try this out...

    - Open two recordsets.
    - one (rs) for temptable and two (rs1) for stock
    -
    do while not rs.eof
    do while not rs1.eof
    if rs!ticker = rs1!ticker then
    ssql = "update stock set name = '" & rs!name & "' where ticker = '" & rs!ticker & "'"
    end if
    rs1.movenext
    loop
    rs.movenext
    loop

    'update the command with the ssql value
    rs.close
    rs1.close


    Any prbs??? Let me know

    Parasu
    Om Nama Sivaya!!!

  7. #7
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    Parasu Raman,

    QBE is only found within Access not in VB. It is a graphical way of constructing SQL statements kinda like creating views in SQL server.

    James

  8. #8
    Addicted Member
    Join Date
    Feb 2001
    Location
    Chennai, India
    Posts
    219
    Oh James,
    I got puzzled. Thanx for that. Ive seen that in Access.

    Good day
    Parasu
    Om Nama Sivaya!!!

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