Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics GP (Archived)

VBA If Statement on window

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hello

When you have Sales Transaction Entry window open there is another window you can drill through to called Sales Debtor Detail Entry.

In the VBA Project under SalesDebtorDetailEntry (Window) the following If Statement works fine -

Private Sub OK_BeforeUserChanged(KeepFocus As Boolean, CancelLogic As Boolean)

If Me.BillToAddressID = "MAIN" Then
Cancel = True
MsgBox "Change 'Bill To Address ID' to Order Number"
End If

End Sub


The Same If Statement Under SalesTransactionEntry (Window) errors

Private Sub Save_BeforeGotFocus(CancelLogic As Boolean)

If Me.DebtorID = "ECOMCASH" And SalesDebtorDetailEntry.BillToAddressID = "MAIN" Then
Cancel = True
MsgBox "Change 'Bill To Address ID' to Order Number"

End If


I can't figure out why, I've done many If statements that look at values in other windows. Any ideas?? Thanks

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: VBA If Statement on window
    Private Sub Save_BeforeGotFocus(CancelLogic As Boolean)
    
    If Me.DebtorID = "ECOMCASH" Then
    Me.UserDefined = 1
    SalesUserDefinedFieldsEntr.Visible = False
    
        If Me.DebtorID = "ECOMCASH" And SalesUserDefinedFieldsEntr.UserDefined4 = "" Then
        Cancel = True
        MsgBox "Enter Order Number in User Defined"
        SalesUserDefinedFieldsEntr.Close


    OK So I've figure out how to open the UserDefined that relates to that Sales Entry. I need to do something like this, I won't have time to to look at it for the next couple of days and close the IF but I'm on the right track now, I feel like I can get it. Thanks for pointing me in the right direction.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: VBA If Statement on window

    Thanks Almas, I must have been typing my response at the same time as you, as I had replied 2 minutes after you at 9.22 saying I had already figured out to use the expansion button, and to close the window within the IF.

    This works for this example, but unfortunately I am also trying to validate a blank user defined field on the transaction if the customer is ECOMCASH, and User Defined has no expansion button.

    Opening the User Defined window has the same issue where it opens up a blank instance of the window not related to that transaction.

    Any ideas?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: VBA If Statement on window

    Hi Tim, in addition to my last post, I tried this -

    Private Sub Save_BeforeGotFocus(CancelLogic As Boolean)
    
    If Me.DebtorID = "ECOMCASH" Then
    Me.ExpansionButton4 = 1
    
    If Me.DebtorID = "ECOMCASH" And SalesDebtorDetailEntry.BillToAddressID = "MAIN" Then
    Cancel = True
    MsgBox "Change 'Bill To Address ID' to Order Number"
    
    Else: SalesDebtorDetailEntry.Close
    
    Save = True
    
    End If
    End If
    
    End Sub


    It's probably not the best way of doing it, if the debtor is ECOMCASH then the other window flashes open, but it seems to work. I'll keep thinking but I don't have any other ideas at the moment. Thanks

  • Suggested answer
    Almas Mahfooz Profile Picture
    Almas Mahfooz 11,003 User Group Leader on at
    RE: VBA If Statement on window

    Mr.Tim has identified the issue and also suggest a great start for this task. But you need to do few more things to achieve this task, and as I always found you a quick learner hope you will do it. : )

    1. You have to not open window but also close on both conditions, when you condition meets and not meet.

    2.You have to close Customer Detail window within your 'If - End IF' block of code otherwise on save button you will get another message saying 'close customer detail window before continuing'.

    3.Add expansion button besides customer ID field and instead of using open command execute the script of this button, so when window will open it will populate with data.

    4.Change your window visibility to false.

    5.Check your condition display message and close the window.

    If CustomerID.Value = "AARONFIT0001" And SalesCustomerDetailEntry.BillToAddressID.Value = "PRIMARY" Then
            Cancel = True
            MsgBox "Change 'Bill To Address ID' to Order Number"
            SalesCustomerDetailEntry.Close
    Else
            SalesCustomerDetailEntry.Close
    End If
  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: VBA If Statement on window

    Thanks for your response Tim but I changed it to -

    SalesDebtorDetailEntry.Open
    If Me.DebtorID = "ECOMCASH" And SalesDebtorDetailEntry.BillToAddressID = "MAIN" Then
    Cancel = True
    MsgBox "Change 'Bill To Address ID' to Order Number"
    
    End If


    And it definitely open up in the foreground. All fields are blank too, even debtor ID, it's like a separate instance of the window has opened and not what would populate if you used the expansion button.

  • Suggested answer
    Tim Foster Profile Picture
    Tim Foster 8,515 on at
    RE: VBA If Statement on window

    I thought about it some more and you might want to include:

    SalesDebtorDetailEntry.Open

    before the "If".  The window won't open in the foreground but will open "behind."

    To force the window open in the foreground:

    SalesDebtorDetailEntry.Show

    @Jon McGhee - It's standard GP.  Tania is in the UK or Australia - substitute "Customer" for "Debtor"

    Tim

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: VBA If Statement on window

    I'm not familiar with the debtor window, is that a third party window?  if so, you'll need to add a reference to the third party window, then you can reference it.  if it is in the GP product, then you'll need to add that debtor window to the vba project.

  • Tim Foster Profile Picture
    Tim Foster 8,515 on at
    RE: VBA If Statement on window

    What is the exact error message?

    Tim

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,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans