+ Reply to Thread
Results 1 to 11 of 11

VBA SQL update statement

  1. #1
    Registered User
    Join Date
    11-26-2010
    Location
    Leeds England
    MS-Off Ver
    Excel 2003
    Posts
    6

    VBA SQL update statement

    Can anyone help with this???

    I am trying to create an update statement to find a field in a database and replace it with data from combo boxes and a text box.

    This is the code that i am currently using.

    Please Login or Register  to view this content.
    any help would be appreciated
    Last edited by DonkeyOte; 11-26-2010 at 01:43 PM.

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: VBA SQL update statement

    And the problem is ... what?

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: VBA SQL update statement

    shawby - welcome to the board though please note that CODE tags should encase your VBA at all times (per Forum Rules).

    Given first post etc I've modified your post for you but going forward please be sure to adhere to the above.

    For more information about these and other tags, found here

  4. #4
    Registered User
    Join Date
    11-26-2010
    Location
    Leeds England
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: VBA SQL update statement

    Quote Originally Posted by Bob Phillips View Post
    And the problem is ... what?
    The problem is that i get a syntax error for the update statement.

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: VBA SQL update statement

    You might first try adding a space prior to the SET command

    Thereafter, though you're seemingly trying to do something regards potential for apostrophe's (see Details variable) you're not as I see it catering for that possibility presently.
    It's also impossible to determine from the code where the variable values are being generated (presumably they have Module/Global level scope)

    Prior to the End If line add the following:

    Please Login or Register  to view this content.
    and review the output in the Immediate Window - this will show the SQL you're trying to perform (ie with variables inserted etc) - post it here.

  6. #6
    Registered User
    Join Date
    11-26-2010
    Location
    Leeds England
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: VBA SQL update statement

    This is what appears in the immediate window

    Please Login or Register  to view this content.
    Last edited by DonkeyOte; 11-29-2010 at 06:47 AM. Reason: removed unnecessary quote

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: VBA SQL update statement

    I don't know which DB platform you're using but do you need a space prior to the WHERE command ?

  8. #8
    Registered User
    Join Date
    11-26-2010
    Location
    Leeds England
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: VBA SQL update statement

    Quote Originally Posted by DonkeyOte View Post
    I don't know which DB platform you're using but do you need a space prior to the WHERE command ?
    unfortunately not that simple

  9. #9
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: VBA SQL update statement

    well without more info. (ie platform, field types, error line etc) there's little we can suggest I'm afraid

    if you step through the code using F8 does the connection actually open correctly - ie the debug occurs on the execution of the SQL itself.

    (it's also difficult to error check given we can't see how the greater majority of the variables in the code are being generated in the first instance)

  10. #10
    Registered User
    Join Date
    11-26-2010
    Location
    Leeds England
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: VBA SQL update statement

    the error occurs when trying to execute the strsql.

    basically all i am doing is taking data from a database, it is being output into a listbox using the following.
    Please Login or Register  to view this content.
    then when i click an item in lst_results it ouputs the data to combo and text boxes
    Please Login or Register  to view this content.
    I then change any of the data that has been output and click an update button which is where i am falling down with the code I have posted above.

    unsure what you mean by the type of database though.

  11. #11
    Registered User
    Join Date
    11-26-2010
    Location
    Leeds England
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: VBA SQL update statement

    Quote Originally Posted by DonkeyOte View Post
    well without more info. (ie platform, field types, error line etc) there's little we can suggest I'm afraid

    if you step through the code using F8 does the connection actually open correctly - ie the debug occurs on the execution of the SQL itself.

    (it's also difficult to error check given we can't see how the greater majority of the variables in the code are being generated in the first instance)
    As this is done entirely in excel 2007 would it help if i sent the file over?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1