Can't execute a SQL statement RRS feed

  • Question

  • I use the following code to append data from MS Excel spreadsheet into MS Access table. In MS Excel I define the data range; for the code below I call it Stage. This used to work in the past; however, now I'm getting an error message stating that the data engine could not find the object Stage. The code breaks on the SQL execution statement. Any ideas why i the data engine is not recognizing Stage anymore and is there any other way to go about this? Many thanks

    Dim rstblODC As New ADODB.Recordset
    Dim rsODC As New ADODB.Recordset
    Dim cn1 As ADODB.Connection

    Dim varODC_Date(), varAmount(), varRecordcount, varODC_Date1 As Variant
    Dim strSource1, strSource2 As String
    Dim intUserMsg, intUserMsg2 As Integer

    Set rstblODC = New ADODB.Recordset

    Set cn = New ADODB.Connection
    Set cn1 = CurrentProject.Connection

    strSource1 = InputBox("Enter Date mm-dd-yyyy", "IPS")
    strSource2 = "C:\Users\Owner\Downloads\Transactions-Download-" & strSource1 & ".xlsx"

    With cn

        .Provider = "Microsoft.ACE.OLEDB.12.0"
        .CursorLocation = adUseClient
        .ConnectionString = "Data Source=" & strSource2 & ";Extended Properties=Excel 12.0;"
    End With

    varSQL = "SELECT * FROM stage"

    cn.Execute varSQL
    rsODC.Source = varSQL

    rsODC.Open , cn

    Saturday, November 11, 2017 3:30 PM

All replies

  • Hello,

    Your code sure looks like VB6 while this forum is solely for VB.NET as stated in the banner when posting your question.

    If this is VB6 then use this forum. If this code is being done in VB.NET then you first need to use VB.NET methods e.g. don't use ADODB RecordSets etc.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Saturday, November 11, 2017 4:27 PM