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

    Unhappy Exporting Data from Ms Access form to Excel sheet

    Hi



    I am trying to export certain values which are in combo box of MS Access to excel sheet. But what's happening is its populating ID of the field instead of Field Name. Any Advice is appreciated.

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by jj1 View Post
    ... its populating ID of the field instead of Field Name...
    What is populating what? Can you post the code you are using and or explain the export process?

  3. #3
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    In your query, you need to join the ID of the Field Name in your main table to the foreign key in your lookup table. Then bring the Named field into the query grid and uncheck the ID field.

  4. #4
    jj1 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    128
    Private Sub cmd_Print_Click()








    Dim objexcel As Excel.Application
    Dim objworkbook As Excel.Workbook
    Dim objxlsheet As Worksheet
    Set objexcel = CreateObject("Excel.Application")
    ''Set objworkbook = objexcel.Workbooks.Open("C:\MSEXCEL_TEST" & "\" & "test.xlsx")
    Set objworkbook = objexcel.Workbooks.Open(CurrentProject.Path & "\" & "test.xlsx")
    Set objxlsheet = objworkbook.ActiveSheet






    objxlsheet.Cells(4, 30) = combo1
    objxlsheet.Cells(5, 30) = combo2

    objexcel.Visible = True
    Set objexcel = Nothing
    End Sub

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Me.combo1.Column(0) = "Value in First Column"

    Me.combo1.Column(1) = "Value in Second Column"

    combo1 = Whichever column is defined as Bound Column in said combo's properties

  6. #6
    jj1 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    128
    That's the code I am using.

    Alan say we have 2 tables Table 1 Main table collecting all Main Information whereas Table 2 say tableDepartment has names of departments. I run a query on table dept. to bring their Dept.ID AND Dept.Name. which fills the combodepart. on the mainform. which then by using the above code. I try to spill dept information populated on the form to Excel. But it takes ID of the Dept. instead of its Name which is showing on the main form

  7. #7
    jj1 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    128
    objxlsheet.Cells(4, 30) = combo1
    objxlsheet.Cells(5, 30) = combo2

    You want me to replace this completely or how do you want me do it. I mean
    I wrote this way

    Me.txtdept.Column(0) = ""

    but its giving run time error 424 object required

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Replace

    objxlsheet.Cells(4, 30) = combo1
    objxlsheet.Cells(5, 30) = combo2

    with something like

    objxlsheet.Cells(4, 30) = Me.combo1.Column(1)
    objxlsheet.Cells(5, 30) = Me.combo2.Column(1)

  9. #9
    jj1 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    128
    Ya its bringing value on excel sheet as false when i used

    objxlsheet.Cells(4, 30) = Me.combo1.Column(1)

    But i think we are getting close to solve

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    You need to determine which column in your combo has the value you want to store in your spreadsheet. The index starts at 0 so 1 is the second column.
    Me.combo1.Column(1)

  11. #11
    jj1 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    128
    Thanks alan It worked

  12. #12
    jj1 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    128
    Thanks for the help Itsme It worked

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

Similar Threads

  1. Exporting into Excel, Automating a Summary Sheet
    By sam.eade in forum Import/Export Data
    Replies: 3
    Last Post: 09-26-2013, 02:14 AM
  2. Help with exporting data from excel to access
    By accessrook in forum Import/Export Data
    Replies: 2
    Last Post: 01-22-2013, 12:58 AM
  3. Import excel sheet data into Ms-access using VBA macros
    By gokul1242 in forum Import/Export Data
    Replies: 2
    Last Post: 10-02-2012, 04:39 AM
  4. exporting data from access to excel
    By tariq nawaz in forum Access
    Replies: 3
    Last Post: 09-06-2012, 09:29 AM
  5. Exporting to Specific Excel Sheet
    By unrealtb in forum Access
    Replies: 2
    Last Post: 01-24-2012, 10:32 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