Results 1 to 5 of 5
  1. #1
    khalid's Avatar
    khalid is offline MS-Access Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2010
    Location
    Kuwait
    Posts
    244

    How to populate local table based on ADODB.Recordset


    Hi Friends,
    I am breaking my head since 2 days to get populate the local table using ADODB.recordset but can not figure it out.
    I have a local table tblLocation_Local which I want to populate/fill with the back-end table tblLocation.

    Both the tables have same structures.

    I have this code:
    Code:
    ' open the connection
    OpenCon ' opens the connection - working correctly
    
    Dim rst As ADODB.Recordset ' declare record set
    
    Set rst = New ADODB.Recordset ' set recordset instance
    
    With rst ' open recordset
        .CursorLocation = adUseClient
        .CursorType = adOpenForwardOnly
        .Open ("Select tblLocation.* FROM tblLocation"), Connection
        CurrentDb.Execute ("Insert INTO tblLocation_Local SELECT * FROM tblLocation") ' ---- HERE I NEED THE RECORDSET DATA TO ENTER IN THE LOCAL TABLE (tblLocation_Local)
    End With
    
    rst.Close
    Set rst = Nothing ' close the recordset
    Set Connection = Nothing ' close the connection
    
    On Error GoTo Err
    Err_Exit:
    Exit Sub
    Err:
    MsgBox Err.DESCRIPTION
    Resume Err_Exit

    I need to get tblLocation_Local populated using ADODB.Recordset method so that it will be faster for users to get data from the local (Static) table instead of being connected all the times to the network.

    Thanks!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Here is how I populate a table with data from another file:
    DoCmd.SetWarnings False
    DoCmd.RunSQL "INSERT INTO PaverData_MajorMRAllYears(SectionID, FAAID) SELECT ID, FAAID FROM [" & strSourcePath & "].zUser_MajorMRAllYears;"
    DoCmd.SetWarnings True
    Don't need ADODB recordset and connection, the strSourcePath deals with that. I use UNC pathing so the string looks like:
    \ \ServerName\path\filename.accdb
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    khalid's Avatar
    khalid is offline MS-Access Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2010
    Location
    Kuwait
    Posts
    244
    Thanks, June! I will give try your suggested code, but my db is password protected and I am wonder if it will work with "strSourcePath"?

  4. #4
    khalid's Avatar
    khalid is offline MS-Access Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2010
    Location
    Kuwait
    Posts
    244

    Thumbs up thumbs up

    Quote Originally Posted by June7 View Post
    Here is how I populate a table with data from another file:
    ......Don't need ADODB recordset and connection, the strSourcePath deals with that. I use UNC pathing so the string looks like:
    \ \ServerName\path\filename.accdb
    Thank you very much June, thumbs up, it works like a charms and it didn't asked for password.

    Many thanks!

  5. #5
    khalid's Avatar
    khalid is offline MS-Access Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2010
    Location
    Kuwait
    Posts
    244
    Quote Originally Posted by June7 View Post
    Here is how I populate a table with data from another file:
    DoCmd.SetWarnings False
    DoCmd.RunSQL "INSERT INTO PaverData_MajorMRAllYears(SectionID, FAAID) SELECT ID, FAAID FROM [" & strSourcePath & "].zUser_MajorMRAllYears;"
    DoCmd.SetWarnings True
    Don't need ADODB recordset and connection, the strSourcePath deals with that. I use UNC pathing so the string looks like:
    \ \ServerName\path\filename.accdb


    Dim strSourcePath As String
    strSourcePath = "C:\01 - Service Contracts-TEST\Service Contracts Back-End.accdb"
    DoCmd.RunSQL "INSERT INTO tblSOF SELECT * FROM [" & strSourcePath & "].tblSOF;"
    Is says that incorrect password... my backend database is password protected. I am using MS-Access 2010, even the front end application was linked with the back-end database with the correct password but this code is giving me the incorrect password error.
    Last edited by khalid; 08-23-2012 at 12:44 AM. Reason: typo + additional code

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

Similar Threads

  1. Populate a field based on combobox selection
    By rscott7706 in forum Access
    Replies: 5
    Last Post: 06-02-2011, 03:18 PM
  2. Replies: 8
    Last Post: 05-17-2011, 04:41 PM
  3. Replies: 1
    Last Post: 09-02-2010, 03:59 PM
  4. populate boxes based on combo box choice
    By Mattm1958 in forum Forms
    Replies: 13
    Last Post: 08-30-2010, 02:09 PM
  5. Form fields export to local table
    By lupis in forum Forms
    Replies: 0
    Last Post: 03-23-2010, 02:38 PM

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