Results 1 to 3 of 3
  1. #1
    anandagrawal444 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2015
    Posts
    2

    Unhappy Update Excel data from access table through SQL in VBA

    Hello,

    I am getting the error "You cannot edit this field as it resides in a linked excel spreadsheet".

    I am trying to create a macro in excel to update data in excel sheet from access table. The code used in VBA is as follows :

    Sub barcode_retrieve()


    Set cn = CreateObject("ADODB.Connection")
    DBPath = "C:\Users\HP\Documents\Access to Excel" & "\Payment_Management2.accdb"
    dbWb = "C:\Users\HP\Documents\Access to Excel\Payment Management.xlsm" ' file name to be changed
    dbWs = "Data Entry"
    scn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DBPath
    dsh = "[" & "Data Entry" & "$]"
    cn.Open scn

    Dim oRs As ADODB.Recordset

    sSQL = "INSERT INTO [Excel 8.0;HDR=YES;DATABASE=" & dbWb & "]." & dsh
    sSQL = sSQL & "SELECT a.[Barcode_No],a.[Barcode_Category] FROM Barcode a where a.Receiving_No is null"

    cn.Execute sSQL

    End Sub

    Please suggest way forward to update excel data from access database.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    create a query to pull data out of the database and put in excel using COPYFROMRECORDSET

    Set oRs = cn.Execute("qsQuery")
    ActiveWorkbook.Worksheets("Sheet1").Range("A1").Co pyFromRecordset rs

  3. #3
    anandagrawal444 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2015
    Posts
    2
    Thanks for the reply. This method will display the results in continuos columns starting from column A1. But I have to display the data in non adjacent columns. Example - Barcode No in Column A in excel, Barcode category in Column C in excel, like that. Through SQL I can match the column names in excel and Access and display the data in the required columns in excel.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 04-15-2015, 10:15 AM
  2. Replies: 4
    Last Post: 12-16-2014, 03:31 AM
  3. Update Existing Access Tables with Data from Excel
    By ChelseaC in forum Import/Export Data
    Replies: 7
    Last Post: 08-10-2014, 04:28 PM
  4. Data update Access to Excel
    By b82726272 in forum Programming
    Replies: 3
    Last Post: 06-19-2014, 09:06 AM
  5. Replies: 7
    Last Post: 04-16-2014, 07:07 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums