Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

VBA Error 1007

(0) ShareShare
ReportReport
Posted on by

I have fields that were added to SOP Entry using Modifier.  I have written VBA code to update those fields and it works fine until either dialog box or another window opens(ie Sales Quantity Shortage Options.  I believe the error occurs because I am trying to set a field on the SOP Entry window and that window is no longer the front window.  I've tried the .Focus event but getting an error 'assignment to constant not allowed'.

Any help would be appreciated.

*This post is locked for comments

  • Verified answer
    Congruent Dynamics Profile Picture
    Congruent Dynamics 735 on at
    RE: VBA Error 1007

    Hi Rick

    Situation:

    You attempted to set a field’s value from “outside” the field (before the field gains focus), such as by using the window’s BeforeOpen or AfterOpen event, or another field’s BeforeUserChanged or AfterUserChanged event.

    When you set the value of a field before the field gains focus, VBA automatically runs the Microsoft Dynamics GP user changed event for the field you’re setting. This is necessary so any accounting system application code associated with these events can verify the field’s value. Although Microsoft Dynamics GP doesn’t

    perform this verification for all fields, they will perform verification for fields that affect business logic (such as an invoice discount percent, or a tax amount) or for add-on-the-fly fields. If the accounting system determines that the field’s value is invalid, it will first display its error dialog, followed by the VBA error dialog.

    Solution:

    There are three ways to avoid this type of error:

    • Whenever possible, set a field’s value from “inside” the field, after it has gained focus, using the field’s AfterGotFocus or BeforeGotFocus field events. If your event procedure sets an invalid value, the accounting system will still display a dialog, but VBA won’t generate the error:

    Private Sub ShippingMethod_AfterGotFocus()

    'Set the Shipping Method field to a value that doesn't exist.

    ShippingMethod = "NEW"

    End Sub

    • If you set the value from “outside” the field, before the field has gained focus, use the Focus method with the setvalue parameter in your event procedure. The Focus method moves the focus to the field, then sets it to the value of the setvalue parameter:

    Private Sub CustomerID_AfterUserChanged()

    'Move the focus to the field, then set the value

    ShippingMethod.Focus("NEW")

    End Sub

    • Only set fields from “outside” the field if you know the accounting system isn’t performing field verification. Microsoft Dynamics GP performs verification for fields that affect business logic (such as an invoice discount percent, or a tax amount) or for add-on-the-fly fields. You can set the value of add-on-the-fly fields only if the add-on-the-fly value already exists as a record (such as an existing shipping method).

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,407 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans