Results 1 to 2 of 2
  1. #1
    richthekid is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2013
    Posts
    1

    how can i switch this code to make a excel result?

    Private Sub cmdPrintInv_Click()


    On Error GoTo p_c
    Dim dbMain As DAO.Database, dbRep As DAO.Database, rsMain As DAO.Recordset, rsRep As DAO.Recordset


    Set dbMain = DBEngine.Workspaces(0).Databases(0)
    Set rsMain = dbMain.OpenRecordset("InvoiceHeader", dbOpenDynaset)


    If rsMain.RecordCount = 0 Then
    rsMain.Close
    Exit Sub
    End If

    If Forms![INVOICE PRINTING FORM]![option] = 1 Then
    Set dbRep = DBEngine.Workspaces(0).Databases(0)
    Set rsRep = dbRep.OpenRecordset("invprint-buy query")

    If rsRep.RecordCount < 1 Then
    rsRep.Close
    Beep
    MsgBox "No Record Found!", 48, gSysName
    GoTo e_p_c
    Else
    DoCmd.OpenReport "INVPRINT-BUY REPORT", acPreview
    End If
    Else
    Set dbRep = DBEngine.Workspaces(0).Databases(0)
    Set rsRep = dbRep.OpenRecordset("invprint-sell query")

    If rsRep.RecordCount < 1 Then
    rsRep.Close
    Beep
    MsgBox "No Record Found!", 48, gSysName
    GoTo e_p_c
    Else
    DoCmd.OpenReport "INVPRINT-SELL REPORT", acPreview
    End If
    End If

    e_p_c:
    rsMain.Close
    dbRep.Close
    dbMain.Close
    Exit Sub
    p_c:
    MsgBox Error$, 48, "BIOS Soft ver. 1 rel 1"
    ''DoCmd.ShowToolbar "Menu Toolbar", A_TOOLBAR_YES
    ''DoCmd.ShowToolbar "Report Toolbar", A_TOOLBAR_NO
    Resume e_p_c


    End Sub

  2. #2
    Dal Jeanis is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    1) if you put the word code in square brackets [] before your code, and /code in square brackets after it, then you won't lose all the indenting, and the code will be more readable.

    2) What part of it? What do you want the excel workbook/worksheet to contain?

    3) On the Report ribbon, there is supposed to be an an export-to-excel button, although in 2007 and 2010 it apparently could only export to .xls, not the 2007/2010 .xlsx format.

    4) For VBA, this thread shows some VBA code that might be able to be adapted- http://www.access-programmers.co.uk/...d.php?t=207442

    5) I'm assuming that you want to replace those two reports with excel sheets. To change the code to export the data, you'd have to look at the reports, see what kind of query they were based on, and that would tell you how to export the data. The above two methods (3) and (4) will give you worksheets that say exactly what the report says, although they will lose much of the formatting. If you want the data to be more usable than that, you'd have to export from a query instead.

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

Similar Threads

  1. Replies: 3
    Last Post: 10-31-2012, 12:14 PM
  2. Make result invisible in Form?
    By RachelBedi in forum Forms
    Replies: 1
    Last Post: 10-23-2012, 09:12 AM
  3. Export Query Result to Excel
    By chewbears in forum Access
    Replies: 11
    Last Post: 11-28-2011, 08:31 AM
  4. Replies: 8
    Last Post: 08-11-2010, 09:20 PM
  5. Replies: 6
    Last Post: 03-27-2010, 11:18 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