Closed Thread
Results 1 to 4 of 4

VBA Help, Using Variables in an SQL Update Statement

  1. #1
    Registered User
    Join Date
    01-07-2016
    Location
    England
    MS-Off Ver
    2003
    Posts
    4

    VBA Help, Using Variables in an SQL Update Statement

    --- Accidental Duplicate Thread, Please Delete ---

    Hi all,

    Im using this code to try and update collumns in a table in Access 2003.

    I cant seem to get the code to work with the variables, Lookup asks to define a parameter even though it is set to the inputbox string, and test causes a type conversion error even though the table is set to Date/time.

    I am very new to VBA And this is my first project.

    I put the msgboxs in to check that the variables were set to the correct values before the UPDATE command, which they are.

    'Update Button
    Private Sub Toggle28_Click()

    Dim Lookup As String
    Dim test As Date

    test = DateValue("Jan 01 2015")

    Dim Update_QCourseData As String

    Lookup = InputBox("Enter your service number", Update, " ")

    MsgBox (test)
    MsgBox (Lookup)


    DoCmd.RunSQL ("UPDATE QCourseData " & _
    "SET [Date Completed] = 'test'" & _
    "WHERE [Service Number] = Lookup")



    End Sub
    Last edited by Critchley; 01-28-2016 at 06:43 AM.

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: VBA Help, Using Variables in an SQL Update Statement

    Hello, welcome to the forum

    When you joined the forum recently you agreed to abide by the Forum Rules, but in haste I fear you might not have actually read them. Please stop and take a moment to read them now. We all follow these rules for the benefit of all, as must you. Thanks.

    (link above in the menu bar)

    Unfortunately:

    This is a duplicate post and as such does not comply with Rule 5 of our forum rules. This thread will now be closed, you may continue in your other thread.

    Also, when posting code, please use code tags

  3. #3
    Registered User
    Join Date
    01-07-2016
    Location
    England
    MS-Off Ver
    2003
    Posts
    4

    Re: VBA Help, Using Variables in an SQL Update Statement

    Sorry about that, I didnt notice. Was having problems with my browser as im at work right now and didnt think it posted first time!

    Dont think i can close this thread myself, else i would.
    Last edited by Critchley; 01-28-2016 at 06:42 AM.

  4. #4
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: VBA Help, Using Variables in an SQL Update Statement

    So thread closed.
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA Help, SQL Update Query using variables
    By Critchley in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-28-2016, 04:52 AM
  2. If statement with two variables
    By leanne2011 in forum Excel General
    Replies: 3
    Last Post: 12-11-2014, 01:11 PM
  3. [SOLVED] IF AND OR Statement with 4 variables
    By Webbers in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 08-24-2012, 03:03 PM
  4. IF Statement with 3 variables
    By garopro in forum Excel General
    Replies: 11
    Last Post: 09-29-2011, 12:23 PM
  5. Update query criteria using variables
    By ot070707 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-26-2011, 05:39 AM
  6. How do i update the values of variables without using the Calculate Sub
    By Saintyboy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-17-2011, 05:05 PM
  7. Too many variables for an if than statement?
    By repke in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 05-02-2006, 12:01 PM

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