+ Reply to Thread
Results 1 to 2 of 2

getting run time error 424 'object required' while running an sql query in VBA

  1. #1
    Registered User
    Join Date
    03-30-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    24

    getting run time error 424 'object required' while running an sql query in VBA

    Hi,

    I am getting an error 424 whenever I'm trying to run the sql query which should filter the data which i have retrieved based on some combo box value. The code snippet looks like this:

    Private Sub cmdShowData_Click()
    'populate data

    Select Case cmbDatagroups.Value

    Case "Insight"
    strSQL = "SELECT * FROM [Insight$] "

    If cmbHLScenarios.Text <> "" Then
    If cmbDatagroups.Text <> "" Then
    strSQL = strSQL & " WHERE [High Level Scenario]='" & cmbHLScenario.Value & "'"
    End If
    End If

    And the common module is :

    Option Explicit
    Public cnn As New ADODB.Connection
    Public rs As New ADODB.Recordset
    Public strSQL As String

    Public Sub OpenDB()
    If cnn.State = adStateOpen Then cnn.Close
    cnn.ConnectionString = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" & _
    ActiveWorkbook.Path & Application.PathSeparator & ActiveWorkbook.Name
    cnn.Open
    End Sub

    Public Sub closeRS()
    If rs.State = adStateOpen Then rs.Close
    rs.CursorLocation = adUseClient
    End Sub

    It would be great if anybody can help me sort out this issue.

    Many thanks in advance.

  2. #2
    Registered User
    Join Date
    03-30-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: getting run time error 424 'object required' while running an sql query in VBA

    Hi Everyone,

    I'm attaching the excel for reference.
    Attached Files Attached Files

+ Reply to Thread

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