web
You’re offline. This is a read only version of the page.
close
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

I have the same question (0)
  • Verified answer
    Congruent Dynamics Profile Picture
    735 on at

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics GP (Archived)

#1
Community Member Profile Picture

Community Member 2

#2
mtabor Profile Picture

mtabor 1

#2
Victoria Yudin Profile Picture

Victoria Yudin 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans