Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics GP (Archived)

Database Admin

Posted on by 105

Need example of VBA code in Report writer

*This post is locked for comments

  • Verified answer
    DHC Profile Picture
    DHC 105 on at
    RE: Database Admin

    Thank you very much Soma.  THAT WORKED PERFECT.

  • Verified answer
    soma Profile Picture
    soma 24,406 on at
    RE: Database Admin

    Write your code for both before Page Header & Report Header only.

    Hope this helps!!!

  • DHC Profile Picture
    DHC 105 on at
    RE: Database Admin

    Thanks for the responses but I have already tried all of that. This is my code:

       Dim rst As New ADODB.Recordset

       Dim cmd As New ADODB.Command

       Dim sqlstring As String

       sqlstring = "SELECT crdtmgr from cn00500 where CUSTNMBR = '" & CustomerNumber & "'"

           ' ADO Command

           cmd.ActiveConnection = cn

           ' adCmdText

           cmd.CommandType = 1

           ' Command

           cmd.CommandText = sqlstring

           ' Pass through SQL

           Set rst = cmd.Execute

       sqlstring = "select CollectorName, CN_Collector_Phone1 from DYNAMICS..CN01400 where CollectorID = '" & strcrdtmgr & "'"

       ' ADO Command

       cmd.ActiveConnection = cn

       ' adCmdText

       cmd.CommandType = 1

       ' Command

       cmd.CommandText = sqlstring

       Set rst = cmd.Execute

           If Not (rst.EOF And rst.BOF) Then

             CollectorName1.Value = rst!CollectorName

             CollectorPhone.Value = rst!CN_Collector_Phone1

           End If

           rst.Close

       Set rst = Nothing

       Set cmd = Nothing

    I am trying to print the Collectoname1 and CollectorPhone on the Customer Statement header which is where the customer number prints. Do I still put my code in the Before Body?  That does not work!!  HELP

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Database Admin

    Hi DHC,

    Please find the below link that will guide you to develop a report using Modifier with VBA.

    www.microsoft.com/.../details.aspx

  • Suggested answer
    soma Profile Picture
    soma 24,406 on at
    RE: Database Admin

    Also have a look on the below link for ADO connection with VBA and Report Writer.

    blogs.msdn.com/.../using-ado-with-vba-with-report-writer.aspx

    Hope this helps!!!

  • Suggested answer
    Naga Kiran Profile Picture
    Naga Kiran on at
    RE: Database Admin

    Hi DHC,

    The below link should help you. Its a well detailed article by David Musgrave on using VBA with Report writer.

    blogs.msdn.com/.../using-vba-with-report-writer.aspx

    Hope this helps.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans