fiogf49gjkf0d
Developing a form in SalesLogix 6.1 Architect, I needed to dynamically populate a group of radio buttons. When a user selected one of the radio buttons, I then needed to obtain the value of that radio button. Seemed easy enough – VB6 provides the property .Value, but alas, the SLX development environment RadioGroup control lacks this property (why?!). The only property that indicates which radio button was selected is .ItemIndex, which is simply an integer (0,1,2,3) representing the radio buttons in the order displayed.
I am populating this particular RadioGroup with some values from the PLUGINS table, specifically those where the Family filed contains ’Letters’. (I also had quite a challenge obtaining only the latest version of each Letter, but that’s a separate story...)
I first populate a recordset with the necessary fields:
Dim objCoverLetters ' Recordset to hold cover letters
Set objCoverLetters = CreateObject("ADODB.Recordset")
Dim strSelectCoverLetters
strSelectCoverLetters = "SELECT P.PLUGINID, P.NAME, P.MODIFIEDDATE " & _
"FROM SYSDBA.PLUGIN P " & _
"WHERE P.FAMILY = 'Letter'" & _
"AND P.USERID IN ('SYST00000001', 'ADMIN')"
objCoverLetters.Open strSelectCoverLetters, & _
Application.GetNewConnection, adOpenForwardOnly, adLockReadOnly
The resulting Letter options will be displayed on a Form for the user to select. Presumably the user will make their choice in a short period of time, but since keeping an ADO recordset open indefinitely is bad coding practice, I needed a way to keep the PLUGINID values available after the recordset is closed. An array was the possible approach, as it doesn’t require an open connection and is relatively light in memory requirements (assuming the result set is small, which it is).
The .GetRows method is very useful to quickly and easily place an entire recordset into an array. After populating the array with the recordset values, the recordset is closed. We then loop through the array and populate the Radio Group with the corresponding array value:
If objCoverLetters.Recordcount > 0 Then
' Use the .GetRows method of the Recordset to place all records into an array
' then, close the Recordset
aryCoverLetters = objCoverLetters.GetRows
objCoverLetters.Close
Set objCoverLetters = Nothing
Dim intUbound
intUBound = UBound(aryCoverLetters, 2)
' Populate the radio group with the cover letters from the array
' The .ItemIndex property of the resulting radio group will correspond to
' the second dimension of the array.
' E.g. aryCoverLetters.ItemIndex = aryCoverLetters( , integer)
Dim intCounter
For intCounter = 0 to intUBound
rdoCoverLetters.Items.Add(aryCoverLetters(1, intCounter) & " (" & _
FormatDateTime(aryCoverLetters(2, intCounter), vbShortDate) & ")")
Next ' intCounter
' Set the ItemIndex to the first radio button
rdoCoverLetters.ItemIndex = 0
Else
MsgBox("There was a problem retrieving the cover letters. Please contact the system administrator.")
End If
The resulting RadioGroup control on the form is shown below:
When the user submits the form, I need the PLUGINID. The RadioGroup’s .ItemIndex property returns the index value of the selected radio button. Since the .ItemIndex of the RadioGroup corresponds to the second dimension of the in-memory array, it is easily retrieved as shown in the following code:
Dim strSelectedCoverLetterID ' String to hold cover letter id
Dim strSelectedCoverLetterName ' String to hold cover letter name
' Get the Cover Letter id and name from the array aryCoverLetters
' using the .ItemIndex property of the radio group
strSelectedCoverLetterID = aryCoverLetters(0, rdoCoverLetters.ItemIndex)
strSelectedCoverLetterName = aryCoverLetters(1, rdoCoverLetters.ItemIndex)
Dynamically populating radio buttons is a fairly common approach and saves rebuilding forms when a new item needs to be added. The SalesLogix IDE doesn’t make it easy to get the value of the Radio Group item that the user has selected other than the .ItemIndex, which is confounding. This approach solved a very perplexing problem – at least for me! Perhaps there was some other way to accomplish this, but I sure couldn’t find it.
|
|