+ Reply to Thread
Results 1 to 2 of 2

Enter inputbox to sql query

  1. #1
    Registered User
    Join Date
    07-10-2013
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    1

    Enter inputbox to sql query

    Need some help with this code. Trying to enter CoName & Year1 into the VBA code below

    Year1 = InputBox("What YEAR are the Actual Figures From?", "Year of GL Use")
    CoName = Range("CoName").Value

    With Selection.ListObject.QueryTable
    .Connection = _
    "ODBC;DRIVER=SQL Native Client;SERVER=W2012-SQL;UID=sa;PWD=sa#12345;DATABASE='& CoName &';"
    .CommandText = Array( _
    "SELECT GLAFS.ACCTID, GLAMF.ACCTDESC, GLAFS.FSCSYR, GLAFS.FSCSDSG, GLAFS.NETPERD1, GLAFS.NETPERD2, GLAFS.NETPERD3, GLAFS.NETPERD4, GLAFS.NETPERD5, GLAFS.NETPERD6, GLAFS.NETPERD7, GLAFS.NETPERD8, GLAFS." _
    , _
    "NETPERD9, GLAFS.NETPERD10, GLAFS.NETPERD11, GLAFS.NETPERD12" & Chr(13) & "" & Chr(10) & "FROM AA1517.dbo.GLAFS GLAFS, AA1517.dbo.GLAMF GLAMF" & Chr(13) & "" & Chr(10) & "WHERE GLAMF.ACCTID = GLAFS.ACCTID AND ((GLAFS.ACCTID>'29%') AND (GLAFS.FSCSYR= '& Year1 &') " _
    , "AND (GLAFS.FSCSDSG='A'))" & Chr(13) & "" & Chr(10) & "ORDER BY GLAFS.ACCTID")
    .Refresh BackgroundQuery:=False
    End With

    Thanks in Advance

    Gerry

  2. #2
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Enter inputbox to sql query

    You must concatenate the variables to your text with double quotation marks:
    Please Login or Register  to view this content.
    Last edited by Izandol; 11-21-2013 at 06:16 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] InputBox to enter data into a cell
    By Nitefox in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 1
    Last Post: 09-18-2013, 01:54 AM
  2. [SOLVED] Create borders to enter the number in InputBox
    By marreco in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-12-2012, 10:40 AM
  3. Excel 2007 using inputbox to enter password
    By CMSS in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-02-2010, 05:29 PM
  4. InputBox to enter file
    By excelvba in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-17-2008, 02:20 PM
  5. Inputbox to enter a %
    By StephanieH in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-10-2006, 11:10 AM

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