Select to view content in your preferred language

Clear controls on Tabs

2391
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
RolfBroch
Frequent Contributor
Oops forgot the _ as in

If pControl.Name <> "Edit1" and _
     pControl.Name <> "Edit2" Then
     pControl.Value = ""
End If

The _ is a line continuation character
0 Kudos
JayKappy
Frequent Contributor
WORKS like a charm......thanks Rolf for your time, patience and examples....
Very appreciated....

My Final Code

Sub ExistingRecord

 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

 ' Give the user option to add new record on existing feature
 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

 ' enable the Button to allow the user to create the historical record Onclick
 Call EnableButton
       
 Else
 '' CALL the function below to clear the form controls.
 Set objEditForm6 = Application.Map.Layers("Outfalls").Forms("EDITFORM")
 ClearValues objEditForm6 
 End If

End Sub


Function ClearValues(byRef frm)
' This function activates each page and clears/sets the control values 

 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 "DOMAINFIELD"
    If pControl.Name = "Field1" Then
     pControl.Value = "NA"
    Elseif pControl.Name = "Field2" Then
     pControl.Value = "None"
    Elseif pControl.Name = "Field3" Then
     pControl.Value = "No"
    Elseif pControl.Name = "Field4" Then
     pControl.Value = "None"
    Elseif pControl.Name = "Field5" Then
     pControl.Value = "None"
    Else
    End If 

    Case "DATETIME"
    pControl.Value = Now

    'Case "EDIT"

    Case "EDIT"
    If pControl.Name <> "cbo_User" and _
     pControl.Name <> "txtUniqueID" and _
     pControl.Name <> "Edit1" and _
        pControl.Name <> "Edit9" Then
     pControl.Value = "none"
    End If 

    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
Thanks Rolf
0 Kudos
RolfBroch
Frequent Contributor
Happy I could help out.

The power of ArcPad is great. With a little bit of code you can get ArcPad to do stuff you need an ArcInfo license of ArcGIS Desktop to do.

Rolf
0 Kudos