Hey All,I take it you're basically trying to get values from a related table to show up in controls on a form. It is my guess that because you are trying to programmatically access the tabs on ArcPad to get to the "related tables" tab, it probably would be waaay easier to just make your values from your related tables just show up in the controls of your Page1 form. Am I feeling you? Here is how you do it. You're gonna have to use some SQL for this, so buckle your safety belts. (It's real easy once you get the syntax.)First, you're going to query your related table dataset for the records that are relevant to whatever you're looking at in your parent dataset. You do this by making DIMming some variable, and setting the following text statement:Dim QueryVariable
QueryVariable = "SELECT [RelatedField1], [RelatedField2], [RelatedField3], ... [RelatedFieldN] FROM [RelatedTableName] WHERE [RelatedTableKeyValue] = " + Cstr(ParentKeyValue)
Just so you know, RelatedField = The fields in your related table that contain the values you're trying to access.RelatedTableName = The ArcCatalog name of your related tableRelatedTableKeyValue = The Field that is related to the key value of your parent table, i.e. If you have 5 related Inspection records for Lamppost number "00001," All 5 Inspection records should contain a field named "Lamppost_Number" that contains the value "00001." This is your "key" value..ParentKeyValue = The field in the Parent Table (i.e. Lampposts) that contains the values that the related table (i.e. Inspections) can "relate" to. ("Cstr" turns any numerical value that might be in the table into a string so that SQL can parse it.)Okay! So we got a nice string here set to a variable! Now we have to EXECUTE it. We're going to store our results in another variable, but this one will end up being a two-dimensional array. (If you're really green, an array is simply a list of values.)Oh, and before we do this, we need to set one more variable to call a reference to our Dataset's "Datasource" object. (This will allow VBScript to "lock on" to our dataset and perform operations.)So, resuming from above:Dim RelatedArray, MyDatasource
Set MyDatasource = Layers("ParentTableName").Datasource
RelatedArray = MyDatasource.Execute(QueryVariable).ToArray(FALSE)
To access an item in your array, simply call the array variable, in this case "RelatedArray,"and list the row (record) you want, followed by a comma, and then the number of the field you want, remembering that the first row or column value starts at "0". For example, if I wanted to list all the returned values of, say, the third field I specified in my query in a listbox on my form, I would use the following:Dim lstResults, ResultArrayCounter, JustSomeVariable
Set lstResults = Applet.Forms("NameOfForm").Pages("Page1").Controls("NameOfListBoxInMyForm")
ResultArrayCounter = 0
For each JustSomeVariable In RelatedArray
lstResults.AddItem RelatedArray(ResultArrayCounter, 2), RelatedArray(ResultArrayCounter, 2)
ResultArrayCounter = ResultArrayCounter + 1
Next
What this code will do is loop through every record that was returned from my initial query of my dataset, and add the result as an item in a listbox. Now some explanation:lstResults = This variable I set to reference a ListBox object in my form. "AddItem" is a method that adds an item that I specify, with the first "argument" being the actual value (code), and the second argument being what actually shows up in my listbox (alias). I want those values to be the same, that's why both arguments are the same. You can find a full list of these "methods" you can use to act upon objects in the ArcPad help.RelatedArray(X,Y) = RelatedArray, again, is a reference to the array I created with my SQL Statement. Because I am attempting to access the third field in my array, I reference "RelatedArray(X,2)" because I know that my first field is zero, my second field is one, and so on.ResultArrayCounter = This is a numerical value that I use to iterate through the rows (records) in my returned array with the "For/Next" statement. It gets set to 0 to begin with, so, remembering that the first value in an array is always 0, it returns the first value, and then the second, until there are no more records left in the array.JustSomeVariable = "For/Next" loops require some variable that they can use to iterate through the array. Just Some Variable will start at zero, and count through the array records until it finishes. It's not really that important though.When this is done, and you enclose all of this in a Sub, whenever you fire this Sub, whether via a button's "OnClick" event, or some other way, like on FormOpen or RecordChange, this will fill your listbox with values from your related table.Those SQL commands can also be used to do stuff like add records to your related dataset, update records of your related dataset, and all sorts of other stuff, and you can use them all the "Datasource.Execute(SQLSTATEMENT).ToArray(False)" command. If you'd like to see what kind of SQL statements are available, google SQL Statements.INSERT INTO is a method that allows you to insert new records into a related table.UPDATE is a method that allows you to update existing related records.Hope this is helpful to you!Love,Brooks