Results 1 to 7 of 7

Thread: SQL call not working

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2000
    Posts
    34

    Post

    I get a run-time error 3075 when running the following sql command...

    Set rs = db.OpenRecordset("UPDATE CustomerProfile SET CustomerProfile.FirstName = " + Chr$(34) + txtFirstName + Chr$(34) + " WHERE (((CustomerProfile.ContactID)= " + Chr$(34) + txtContactID + Chr$(34) + " ")

    Any suggestions as to why this doesn't work?

    Thanks,
    Dave

  2. #2
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    363

    Post

    Have you tried pasting the string into a textbox to make sure it has the correct syntax? From there, I would run directly from the database to make sure it's working before coming back into vb.

    Good luck,
    Wade

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2000
    Posts
    34

    Post

    This is the sql view in Access:

    UPDATE CustomerProfile SET CustomerProfile.FirstName = "Dave"
    WHERE (((CustomerProfile.ContactID)="5"));

    It works fine....but calling it from vb requires some tweaking in order to pull the information from the txtFirstName and txtContactID text boxes...any suggestions?

    Thanks,
    Dave

  4. #4
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105

    Post

    Try this instead:

    Code:
    dim sQry as string
    
    sQry= "UPDATE CustomerProfile SET FirstName = '" & txtFirstName & "' WHERE ContactID= '" & txtContactID & "'"
    
    Set rs = db.OpenRecordset(sQry)
    [This message has been edited by JHausmann (edited 01-20-2000).]

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2000
    Posts
    34

    Post

    JHausmann,

    I put the code you wrote into my application. It gives an error message, "Invalid Operation" and highlights the following line...

    Set rs = db.OpenRecordset(sQry)

    Any suggestions?

  6. #6
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    the OpenRecordset method only works for SELECT queries.

    Because we are doing an UPDATE, we need to use

    DB.Execute sQry

    Where DB is your DAO database object. Also, if ContactID is a numeric field, you don't want to have quotes around that value...

    HTH

    Tom

  7. #7

    Thread Starter
    Member
    Join Date
    Jan 2000
    Posts
    34

    Post

    Thank you so much! Works great! Now I can move forward with the application!

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