Results 1 to 9 of 9

SQL Query in VBA throwing mismatch error

Threaded View

  1. #1
    Registered User
    Join Date
    08-16-2010
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    27

    SQL Query in VBA throwing mismatch error

    I am getting data type mismatch in criteria error in this code..

    please help

        Application.ScreenUpdating = False
        Application.ScreenUpdating = False
        graph3.Unprotect
        Dim winchoice, tierchoice, originalchoice, reg_terr_choice, decilechoice As String
        Graph_data.Range("graph_r1").Clear
        If terr_master_list.Range("pivotfield_calledon").Value = "All" Then
            winchoice = "1, 2"
        Else
            winchoice = terr_master_list.Range("pivotfield_calledon").Value
        End If
        If terr_master_list.Range("pivotfield_decile").Value = "All" Then
            decilechoice = "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10"
        Else
            decilechoice = terr_master_list.Range("pivotfield_decile").Value
        End If
        If terr_master_list.Range("pivotfield_original").Value = "All" Then
            originalchoice = "'Y', 'N'"
        Else
            originalchoice = " '" & terr_master_list.Range("pivotfield_original").Value & "' "
        End If
        If terr_master_list.Range("tierchoice").Value = "All" Then
            tierchoice = "1, 2"
        Else
            tierchoice = terr_master_list.Range("tierchoice").Value
        End If
        If terr_master_list.Range("pivotfield_Region").Value = "All" Then
            reg_terr_choice = "5410, 5420, 5430"
        ElseIf terr_master_list.Range("graph3_1_5choice").Value <= 4 Then
            reg_terr_choice = terr_master_list.Range("pivotfield_Region").Value
        Else
            reg_terr_choice = " '" & terr_master_list.Range("pivotfield_Region").Value & "' "
        End If
            Data_Range = GetDataRange_Query([Graph_data], Range(Range(Range("graph_dataStart"), Range("graph_dataStart").Offset(5000, 0).End(xlUp)), Range(Range("graph_dataStart"), Range("graph_dataStart").End(xlToRight))))
        If terr_master_list.Range("pivotfield_Region").Value = "All" Or terr_master_list.Range("pivotfield_Region").Value = 5410 Or terr_master_list.Range("pivotfield_Region").Value = 5420 Or terr_master_list.Range("pivotfield_Region").Value = 5430 Then
            strsql = "Select * From " & Data_Range & " Where [Region_Code] in (" & reg_terr_choice & ") AND  [Decile] in (" & decilechoice & ") AND  [Win_Called_on] in (" & winchoice & ") AND [Account_Tier] in (" & tierchoice & ") AND [Original_Account] in (" & originalchoice & ");"
        Else
            strsql = "Select * From " & Data_Range & " Where [Territory_Code] in (" & reg_terr_choice & ") AND  [Decile] in (" & decilechoice & ") AND  [Win_Called_on] in (" & winchoice & ") AND [Account_Tier] in (" & tierchoice & ") AND [Original_Account] in (" & originalchoice & ");"
        End If
        PasteSQl strsql, [graph_strt]
        graph3.Protect AllowSorting:=True, AllowFiltering:=True
    Last edited by pike; 04-06-2011 at 06:07 AM.

Thread Information

Users Browsing this Thread

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

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