Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics SL forum
Unanswered

Custom validation on button click VBTools

Posted on by 1,245

Hello Everyone.

I'm looking at injecting a custom validation code using customization manager in Automatic Invoice Creation (BI.AIC.00) screen.  I want to validate few fields on this screen when "Create Invoices" button is clicked.  To this effect, I have managed to successfully place a click event on this button.  See the code below:

 Private Sub cBegProcessing_Click()
    Dim S As String
    S = GetObjectValue("cGLSub")
    If Not ChkGLSub(S) Then
        MsgBox "GL validation fails"
        ' I want to stop further processing of this here... How?
    End If
End Sub

In my code, look at the comment "I want to stop...". Here what should I write so that this event does not move forward and go about creating invoices.

 TIA. 

Nayan

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Custom validation on button click VBTools

    I would like to try and use SetObjectValue in VB.Net code to set value to a control as MyApp.Controls("ccustid").Value = "12321" is not setting value. The control on VB.net is showing as enabled = false. I've tried setting to true however property is not changing.

  • Nayan Mansinha Profile Picture
    Nayan Mansinha 1,245 on at
    Re: Re: Re: Re: Re: Custom validation on button click VBTools

    that worked.  thanks Paul!

  • Paul Phillips Profile Picture
    Paul Phillips 590 on at
    Re: Re: Re: Re: Custom validation on button click VBTools

    No problem on the terminology - I just wanted to make sure that other folks who read this post don't get confused. The two are very similar and it is a common mixup.

    Instead of using SetObjectValue, this might work instead:

    sivMyApp.Controls("cBegProcessing").value = True

    sivMyApp should be a global reference to the Object Model SIVApplication object, which in this case refers to the screen itself in VBA. I don't think you will need to declare it first before using it. If memory serves sivMyApp has gone away in later versions, but for 6.5 hopefully this will work for you. I don't have a 6.5 environment handy at the moment to test.

     

    Regards,

    Paul

     

     

  • Nayan Mansinha Profile Picture
    Nayan Mansinha 1,245 on at
    Re: Re: Re: Custom validation on button click VBTools

    Forgot to mention that I'm on SL 6.5. 

  • Nayan Mansinha Profile Picture
    Nayan Mansinha 1,245 on at
    Re: Re: Custom validation on button click VBTools

    Thanks Paul.  I did what you have mentioned but SetObjectValue on cBegProcessing is throwing System Message 9203 "The specified object is not user enterable: SetObjectValue". 

    And sorry for mixing up VBTools and Customization Manager.

    TIA

    Nayan

  • Paul Phillips Profile Picture
    Paul Phillips 590 on at
    Re: Custom validation on button click VBTools

    One quick clarification of terminology to avoid confusion - VBTools (SL SDK in v7) is used for creating new SL application screens using visual basic 6 (Solomon v6.5 and before) or VB.net (SL v7). Customization manager / VBA is used for modifying existing screens at run-time without recompiling them. VBA runs as a layer on top of an existing screen.

    I don't believe that it is possible to override the base screen's events in VBA. Even if it were, it would not be advisable because it could interfere with the standard processing logic and have bad side effects.

    In order to accomplish what you want, the typical pattern that SL customizers follow is to add a new button to the screen and set the existing cBegProcessing button's 'visible' property to false. Then make the new button have the same caption as the old, and move it to where the old one was.

    Then, you can put whatever logic you desire in the button. Once you have finshed your custom validation code, you can click the hidden original button to start processing by setting its value to true, e.g.:

    serr1 = SetObjectValue("cBegProcessing", "True")

    It is important that the button still be on the form because some other applications such as object model or application server may be launching the screen and automating it, expecting the button to be there and enabled.

    From the user's standpoint, they won't see any difference in the screen as long as you make the caption, button location, style, etc. the same for your replacement button.

    Regards,
    Paul

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

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

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,564 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,651 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans