Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Item.Name by Reference

Status
Not open for further replies.

jbusse

Programmer
Dec 17, 2002
4
US

I have a SQL query that returns the names selected fields on the current form. I want to retrieve the text value found in the selected fields on the form.

Example Return Value:
fieldName = "addressDisplay"
fieldType = "text"

On the current form, the addressDisplay.text value is:
"123 Elm Street"

I want my outputValue variable to be "123 Elm Street" at the location denoted by *** below.

- - - - - - - - - -

queryString = "SELECT fieldName,fieldType " & _
"from labelFields where " & _
"labelName = '" + labelName + "'"
' Execute the Query
' outputTable is a DataTable
outputTable = sf.getSQLData(queryString)

If Not outputTable Is Nothing Then
' Grab the location values
currRows = outputTable.Select(Nothing, Nothing, DataViewRowState.CurrentRows)

If (currRows.Length < 1) Then
locationSelection.Items.Add(&quot;No Current Rows Found&quot;)
Else
' Loop through the bookmarks and replace the values
For Each dRow In currRows
fieldName = Trim(dRow.Item(&quot;fieldName&quot;).ToString)
fieldType = Trim(dRow.Item(&quot;fieldType&quot;).ToString)

Select Case fieldType
Case &quot;text&quot;
outputValue = *** fieldName.Text ***
Case &quot;128B&quot;
outputValue = *** code128(fieldName.Text) ***
End Select

Next 'For Each dRow In currRows
End If 'currRows.Length < 1
End If 'Not outputTable Is Nothing

- - - - - - - - - - -

I hope this explains the problem.
 
There's no way to index the Form's Controls collection by name -- only by index value.

So for every row you get back from the database, you'd have to locate the equivalant control by iterating through the collection. Try writing a function like this:
Code:
Function GetControlByName(ByVal Controls As ControlCollection, ByVal ControlName As String) As Control
   Dim i As Integer

   For i = 0 To Controls.Count - 1
      If Controls(i).Name = ControlName Then
        GetControlByName = Controls(i)
        Exit Function
      End If
   Next i
   GetControlByName = Nothing
End Function
You may need to change a few things in the code -- like the start & end range for the controls collection index (Sorry, I'm a C# guy, so I think in terms of 0..n-1)

You can also change the string compare function to use the culture invariant comparison method of the String object (in case you're doing multinational development).

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top