help with vbscript sub routine to be called with onfeaturecreated event

3236
0
05-06-2015 03:19 PM
BenjaminGrover
New Contributor II

What I'm trying to accomplish is to increment my Edit_Count counter from the event onfeaturecreated in the Layer events, rather than at the close or change of value for each combo box and edit box that makes up my address field (edit_add_combined).   I originally had a version of this increment counter embedded in the subroutine which concatenated address field from my edit and combo boxes of bulding num, street direction (N,NE, etc....), st name(Main, Broadway, etc...) and st type (Ave, St, Cir, etc...)... The counter functioned perfectly on the creation of new features.  I stored a global variable of the full completed address on the click of OK in the form, which was then compared to the concatenated address on the next created feature, and if they were different, my script reset the counter field to 1, and if they were the same, my script added 1 to the stored global variable of the last created feature.  (The idea is to count how many points are collected per property/address parcel.) The issue was this:  if they went back to an already created feature to edit anything, and even so much as clicked on one of the edit/combo boxes for the address fields, it would re-calculate the counter field of an already completed and correct feature based on what was created last.  SO, i'm trying to put the code that adds 1 to my saved global count variable on the onfeaturecreated event so this wont be an issue with editing existing features.  But it will not work the way I have it set up.. I think i'm referencing things incorrectly with it being a Layer event rather than a Form event, but I havent been able to find any help on how to execute and reference editboxes and comboboxes from a particular Form page on a Layer event.

This is the code I have that functioned correctly on my Form events to concatenate my address fields and increment my count field based on the comparison of the complete address field to the global variable stored from the previous completed address field.. :

Sub CombineAddFlds()

Dim objControl, objPage, StTyp, AddNum, StDir, StName, EditAddComb, EditCount

Set objPage = ThisEvent.Object.Parent

StTyp = objPage("Combo_StType").Value

AddNum = objPage("Edit_Addr_Hou2").Value

StDir = objPage("Combo_St_Dir").Value

StName = objPage("Combo_StName").Value

objPage.Controls("Edit_Add_Combined").Value = Addnum + " " + StDir + " " + StName + " " + StTyp

'added following code to combine sub-routines: "combine addr fields" and "on addr change count increment return to 1"

If objPage.Controls("Edit_Add_Combined").Value = Application.UserProperties("VarAddComb") Then

     objPage.Controls("Edit_Count").Value = (Application.UserProperties("LastCount") + 1)

     Else objPage.Controls("Edit_Count").Value = 1

End If

End Sub

This code is what I have tried calling from the Layer event onfeaturecreated:

Sub OnCreateCounter()

       Dim objPage

       Set objPage = ThisEvent.Object.Pages("PAGE2").Controls

    If objPage.Controls("Edit_Add_Combined").Value = Application.UserProperties("VarAddComb") Then

       objPage.Controls("Edit_Count").Value = (Application.UserProperties("LastCount") + 1)

       Else objPage.Controls("Edit_Count").Value = 1

    End If

End Sub

0 Kudos
0 Replies