Results 1 to 4 of 4
  1. #1
    jj1 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    128

    Recordset with paramter query and export it to excel

    Hi



    I am trying to run this recordset with parameter query and export to excel. Problem I am getting is it is sending the ID of employee name and exporting row wise instead of column wise.


    Code:
      Dim dbMyDatabase As DAO.Database
       Dim rsMyRecords1 As DAO.Recordset
       Dim qdMyParameters1 As DAO.QueryDef
       Dim iIndex As Integer
       Dim iFound As Integer
       Dim oExcel As New Excel.Application
       Dim oWb As Excel.Workbook
       Dim oSheet As Excel.Worksheet
       If IsNull(Me.cbozoneteamshift) Then
          MsgBox ("No valid Zone/Team/Shift selected")
          'GoTo 500
       End If
       oExcel.Workbooks.Open (CurrentProject.Path & "\" & "JobMatrix.xlsx")
       oExcel.Visible = True
       Set oWb = oExcel.Workbooks(1)
       Set oSheet = oExcel.ActiveWorkbook.Worksheets("ROTC")
       oSheet.Unprotect ("qwerty")
       Set dbMyDatabase = CurrentDb()
       oSheet.Cells(3, 3) = Forms!JobMatrix!cbozoneteamshift.Column(1)
       oSheet.Cells(4, 3) = Date
       Set rsMyRecords1 = dbMyDatabase.OpenRecordset("tblZone/EmployeeJunction")
       Set qdMyParameters1 = dbMyDatabase.QueryDefs("EmployeesByZone")
       qdMyParameters1.Parameters(0) = _
           Forms!JobMatrix!cbozoneteamshift
       Set rsMyRecords1 = qdMyParameters1.OpenRecordset
     
    
       iIndex = 0
       Do
          With oSheet
             .Cells(8, 3 + iIndex) = rsMyRecords1("EmployeeID")
          End With
    
          iIndex = iIndex + 1
          rsMyRecords1.MoveNext
       Loop Until rsMyRecords1.EOF = True
       iIndex = 0
       iFound = 0
       iMax = rsMyRecords1.RecordCount
            oSheet.Protect ("qwerty")
            Set oSheet = Nothing
            Set oWb = Nothing
            Set oExcel = Nothing
          rsMyRecords1.Close
          qdMyParameters1.Close
          dbMyDatabase.Close
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    That is odd because the Cells method is incrementing the column index.
    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
    jj1 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    128
    and also when name values are populated they are populating as ID instead of name.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Not seeing where code populates name, just EmployeeID.
    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.

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

Similar Threads

  1. Replies: 3
    Last Post: 10-22-2014, 02:38 AM
  2. Export Recordset to Excel
    By bimcompu in forum Programming
    Replies: 1
    Last Post: 01-08-2014, 05:53 PM
  3. Replies: 7
    Last Post: 04-25-2013, 03:47 PM
  4. Export Query to Excel
    By Leon_SF in forum Import/Export Data
    Replies: 7
    Last Post: 03-21-2012, 09:07 PM
  5. Replies: 3
    Last Post: 10-07-2011, 07:49 AM

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