web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

Running SQL server Stored procedure and exporting the executed data into excel

(0) ShareShare
ReportReport
Posted on by 35

We are using GP 2015. We did our year end updates and have imported all the customized reports back.

There is a stored procedure that is called from within GP's (Using VBA macro). The macro then captures the data from the stored procedure(SQL Server Management studio) and exports it to Excel. This is done via a form from within Great Plains.

For some reason the VBA code errors out and states that "Compire Error: User-defined type not defined"

It seems to be stopping at a "Dim" function that requests Excel to open up.

Any ideas on how to fix this? Do I need to correct something in Great Plains?

I have temporarily run the SP from SQL and extracted the data.

Hiren

*This post is locked for comments

I have the same question (0)
  • MG-16101311-0 Profile Picture
    26,225 on at

    It's very hard to troubleshoot code when you don't let us see the code.

  • rajaa_29 Profile Picture
    35 on at

    Private Sub GenerateFile()

    On Error GoTo err_trap

    'Generate x File if x Checkbox is marked

    If Me.CBa.Value = True Then

       cmd.CommandText = "EXEC dbo.ipg_PayrollFilea '" & Trim(Me.TbBeginDate.Value) & "', '" & Trim(Me.TbEndDate.Value) & "'"

       'cmd.CommandText = "SELECT * FROM SOP10100"

    End If

    'Generate y File if y Checkbox is marked

    If Me.CBb.Value = True Then

       cmd.CommandText = "EXEC dbo.ipg_PayrollFileb '" & Trim(Me.TbBeginDate.Value) & "', '" & Trim(Me.TbEndDate.Value) & "'"

       'cmd.CommandText = "SELECT * FROM POP10100"

    End If

    Set rst = cmd.Execute

    Dim oApp As New excel.Application

    Dim oBook As Office

    Dim oSheet As New excel.Worksheet

    Set oBook = oApp.Workbooks.Add

    Set oSheet = oBook.Worksheets(1)

    'Add the field names in row 1

    Dim i As Integer

    Dim iNumCols As Integer

    iNumCols = rst.Fields.Count

    For i = 1 To iNumCols

       oSheet.Cells(1, i).Value = rst.Fields(i - 1).Name

    Next

    'Add the data starting at cell A2

    oSheet.Range("A2").CopyFromRecordset rst

    'Format the header row as bold and autofit the columns

    With oSheet.Range("a1").Resize(1, iNumCols)

       .Font.Bold = True

       .EntireColumn.AutoFit

    End With

    'Open the Excel Workbook for the user

    oApp.Visible = True

    oApp.UserControl = True

    'Close the Database and Recordset

    rst.Close

    Exit Sub

    err_trap:

       MsgBox Err.Number & " " & Err.Description

       CancelLogic = True

       KeepFocus = True

    Exit Sub

    End Sub

  • rajaa_29 Profile Picture
    35 on at

    Hi Mariano,

                      Here is the code. The code stops at the paragraph where Excel is supposed to open. We had upgraded GP's and this started to happen after it. For some reason VBA does not recognize " Dim oAPP as New Excel.application"

  • Suggested answer
    MG-16101311-0 Profile Picture
    26,225 on at

    It seems during the upgrade, your VBA project lost the references to the Microsoft Excel Object Library and the Microsoft Office Object Library. To restore these, follow these steps:

    1. Open the VBA Editor

    2. Under Tools, click on References

    3. Locate Microsoft Excel {versionNumber} Object Library and mark

    4. Locate Microsoft Office {versionNumber} Object Library and mark

    5. Recompile your project to make sure there are no errors, by going to Debug > Compile Microsoft_Dynamics_GP

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics GP (Archived)

#1
talty09 Profile Picture

talty09 2

#1
Anthony Beatty Profile Picture

Anthony Beatty 2

#3
CP04-islander Profile Picture

CP04-islander 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans