Results 1 to 4 of 4

Thread: UPDATE and INSERT SQL questions

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 1999
    Posts
    80

    Question

    Hi,

    How do I use UPDATE and INSERT type SQL statements in a database and recordset declared in code?

    I use the following for SELECT statements:

    Code:
    SQL = "SELECT * FROM Employees"
    Set db = OpenRecordset(dbPath)
    Set rs = db.OpenRecordset(SQL)
    I can't seems to get rs.Execute(SQL) to work. What am I doing wrong?

    Thanks in advance.

  2. #2
    Lively Member
    Join Date
    Mar 2000
    Location
    Germany
    Posts
    84

    I've been doing it this way:

    Code:
    StrSQL = "INSERT INTO " & Table_Name & _
                            " (" & StrFields & ") " & _
                            " VALUES (" & StrValues & ")"
    'Debug.Print StrSQL
    
    Dim cmd as ADODB.Command
    Set cmd = New ADODB.Command
    cmd.ActiveConnection = cnDB
    cmd.CommandText = StrSQL
    cmd.Execute
    Set cmd = Nothing

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 1999
    Posts
    80

    Smile

    Thanks Nina.

  4. #4
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    I do it in DAO as this:

    Code:
    SQL = "Update ......"
    dbMaster.Execute SQL
    If you are not getting this right, maybe you are using parenthesis around the query, like:

    Code:
    SQL = "Update ...."
    dbMaster.Execute(SQL)
    Try omitting the parenthesis and it should work.




    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

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