Select to view content in your preferred language

Clear controls on Tabs

2384
13
05-06-2011 05:55 AM
JayKappy
Frequent Contributor
In my app the user clicks on an existing feature.  it asks them to create a historical record, if yes it runs some SQL statement that updates a related table.  After the save (which works fine) I am trying to clear/set the existing controls on the 3 tabs in the form to either 0, none, NA.
I am using the below code and for the most part it is working...I can modify the values on TAB 1, but for some reason the controls on TAB 2 and TAB 3 are not being effected?

Anyone know why?

THanks

Sub ClearForms

 Dim objRS1, objEditForm1, objSelLayer1
 Set objSelLayer1 = Map.SelectionLayer
 Set objRS1 = objSelLayer1.Records
 objRS1.Bookmark = Map.SelectionBookmark

 ' Clear Page 1
 Dim objEFPageOneControls1
 Set objEditForm1 = application.map.layers("Outfalls").forms("EDITFORM")
 Set objEFPageOneControls1 = objEditForm1.Pages("page1").Controls
  objEFPageOneControls1("txtSEDDIST_FT").Value = "0"
  objEFPageOneControls1("txtSEDLGTH_FT").Value = "0"
  objEFPageOneControls1("txtSEDWDTH_FT").Value = "0"
  objEFPageOneControls1("txtOFWTRHT_IN").Value = "0"

 ' Clear Page 2
 Dim objEFPageOneControls2
 Set objEFPageOneControls2 = objEditForm1.Pages("page2").Controls
  objEFPageOneControls2("txtCOMMENTS").Value = "none"
  objEFPageOneControls2("Edit1").Value = "none"
  objEFPageOneControls2("Edit2").Value = "none"

 ' Clear Page 3
 Dim objEFPageOneControls3
 Set objEFPageOneControls3 = objEditForm1.Pages("page3").Controls
  objEFPageOneControls3("image1").Value = "none"
  objEFPageOneControls3("image2").Value = "none"
  objEFPageOneControls3("image3").Value = "none"
End Sub
Tags (3)
0 Kudos
13 Replies
JayKappy
Frequent Contributor
This is driving me nuts...why cant I set the controls on the 2nd and 3rd tabs?

THanks

Funny thing is that I can disable the controls the same way....

Sub DisableTab1and2

 Dim objRS6, objEFPageOneControls6, objEditForm6, objSelLayer6
 Set objSelLayer6 = Map.SelectionLayer
 Set objRS6 = objSelLayer6.Records
 objRS6.Bookmark = Map.SelectionBookmark

 Set objEditForm6 = application.map.layers("Outfalls").forms("EDITFORM")
 Set objEFPageOneControls6 = objEditForm6.Pages("page1").Controls
 objEFPageOneControls6("cbo_User").Enabled = False
 objEFPageOneControls6("txtUniqueID").Enabled = False
 objEFPageOneControls6("Edit1").Enabled = False
 objEFPageOneControls6("Edit9").Enabled = False
 objEFPageOneControls6("txtSEDDIST_FT").Enabled = False
 objEFPageOneControls6("txtSEDLGTH_FT").Enabled = False
 objEFPageOneControls6("txtSEDWDTH_FT").Enabled = False
 objEFPageOneControls6("txtOFWTRHT_IN").Enabled = False

 Dim objEFPageOneControls12
 Set objEFPageOneControls12 = objEditForm6.Pages("page2").Controls
 objEFPageOneControls12("txtCOMMENTS").Enabled = False
 objEFPageOneControls12("Edit1").Enabled = False
 objEFPageOneControls12("Edit2").Enabled = False

 Dim objEFPageOneControls3
 Set objEFPageOneControls3 = objEditForm6.Pages("page3").Controls
 objEFPageOneControls3("image1").Enabled = False
 objEFPageOneControls3("image2").Enabled = False
 objEFPageOneControls3("image3").Enabled = False
End Sub

0 Kudos
RolfBroch
Frequent Contributor
In order to change a value/text on a control on a page the page in question MUST be the active page. You can change the property of a control (enable, disable etc..) without the page beeing active but not the value/text of the control.

Rolf
0 Kudos
JayKappy
Frequent Contributor
Can I make the page active programmatically?
And then clear the controls...sort of wipe the form
0 Kudos
RolfBroch
Frequent Contributor
Something like this:

Sub ClearForms

Dim objRS1, objEditForm1, objSelLayer1
Set objSelLayer1 = Map.SelectionLayer
Set objRS1 = objSelLayer1.Records
objRS1.Bookmark = Map.SelectionBookmark

Dim pPage

' Clear Page 1
Dim objEFPageOneControls1
Dim pFirstPage
Set objEditForm1 = application.map.layers("Outfalls").forms("EDITFORM")
Set pFirstPage = objEditForm1.Pages("page1")
pFirstPage.Activate
Set objEFPageOneControls1 = objEditForm1.Pages("page1").Controls
  objEFPageOneControls1("txtSEDDIST_FT").Value = "0"
  objEFPageOneControls1("txtSEDLGTH_FT").Value = "0"
  objEFPageOneControls1("txtSEDWDTH_FT").Value = "0"
  objEFPageOneControls1("txtOFWTRHT_IN").Value = "0"

' Clear Page 2
Dim objEFPageOneControls2
Set pPage = objEditForm1.Pages("page2")
pPage.Activate
Set objEFPageOneControls2 = objEditForm1.Pages("page2").Controls
  objEFPageOneControls2("txtCOMMENTS").Value = "none"
  objEFPageOneControls2("Edit1").Value = "none"
  objEFPageOneControls2("Edit2").Value = "none"

' Clear Page 3
Dim objEFPageOneControls3
Set pPage = objEditForm1.Pages("page3")
pPage.Activate
Set objEFPageOneControls3 = objEditForm1.Pages("page3").Controls
  objEFPageOneControls3("image1").Value = "none"
  objEFPageOneControls3("image2").Value = "none"
  objEFPageOneControls3("image3").Value = "none"
pFirstPage.Activate
End Sub


Here is a function I use quite frequently. It will clear comboboxes (but keep the drop down values), empty text controls, set date controls to todays date and clear checkboxes on all pages for the form being passed to the function.

Function ClearValues(byRef frm)
  Dim pControl, pPage
  For Each pPage In frm.Pages
    pPage.Activate

    For Each pControl In pPage.Controls
      Select Case pControl.Type
        Case "COMBOBOX"
          If pControl.ListCount = 1 Then
            pControl.ListIndex = 0
          Else
            pControl.ListIndex = -1
          End If

        Case "DATETIME"
          pControl.Value = Now

        Case "EDIT"
          pControl.Value = ""

        Case "CHECKBOX"
          pControl.Value = 0 'False
      End Select
    Next
  Next

  frm.Pages(1).Activate

  ' CleanUp
  Set pControl = Nothing
  Set pPage = Nothing
End Function
0 Kudos
JayKappy
Frequent Contributor
AWESOME....THANKS MAN....

How would I call the fnuction from the code..... just call this function from here?
I am a bit confused how to call an dinteact with the function.....from what I see all I have to do is fire the function off and it will walk thorough the pages and set them....and then return to the first page...
Just cant figure out how to call it....Functions confuse the heck out of me....I dont understand what I am passing from the call to the function and back


Dim YesOrNoAnswerToMessageBox
Dim QuestionToMessageBox

QuestionToMessageBox = "Do you want to enter new data?" & VBNewline & VBNewline & "Are you sure you want to create the historical record now"

YesOrNoAnswerToMessageBox = MsgBox(QuestionToMessageBox, vbYesNo, "VBA Expert or Not")

If YesOrNoAnswerToMessageBox = vbNo Then
Exit Sub
Else
' CLear all the Textboxes and Comboboxes, comments, images and video
'Call ClearForms
CALL THE FUNCTION

End If
0 Kudos
RolfBroch
Frequent Contributor
As long as you have the form object you can call it like this

Set pForm = Application.Map.Layers("Outfalls").Forms("EDITFORM")
ClearValues pForm
0 Kudos
JayKappy
Frequent Contributor
Thanks again...was able to make that work...
Although in my application I have a couple textboxes on the form that cannot be changed...The contain Unique Ids etc.  So I have to do it the original way I was trying...which is also working

BUT your function will come in very handy on other projects....I thank you for your time, patience and examples....

THanks again....
0 Kudos
RolfBroch
Frequent Contributor
If you for example has an edit control that you want to skip add this statement under the case statement for the edit control

Case "EDIT"
If pControl.Name <> "theNameOfYourControl" Then
pControl.Value = ""
End If

and if there are more EditControls just add them like this
Case "EDIT"
If pControl.Name <> "theNameOfYourControl" and
   pControl.Name <> "theNameOfAnotherControl" Then
pControl.Value = ""
End If
0 Kudos
JayKappy
Frequent Contributor
I am getting a syntax error with this....anything you can see?  Edit1 and Edit2 are on the first tab...I dont think this error is arising because Edit1 and Edit2 are not on pages 2 and 3....?

Microsoft VBScript error
Syntax error
Source Text Unavailable


Case "EDIT"
If pControl.Name <> "Edit1" and
     pControl.Name <> "Edit2" Then
     pControl.Value = ""
End If 
0 Kudos