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!

Combo Box changing the ItemData or NewIndex property to accept text

Status
Not open for further replies.

denchyb

Programmer
Oct 19, 1999
2
US
*database combo box question*<br>
<br>
These routines works fine if RsUserAux(&quot;d_id&quot;) is an integer<br>
all the time.<br>
<br>
May problem is if RsUserAux(&quot;d_id&quot;) is a string containing<br>
any value like 12, a, d, 4, 23333.8888, hi, etc, etc.<br>
How can I modify may routines to look at the RsUserAux(&quot;d_id&quot;) values that I mentioned.<br>
<br>
This routine creates the combo box<br>
<br>
'******************************************************<br>
Sub CreateDepartmentCombo(ByRef objDepartment As ComboBox)<br>
<br>
Dim RsUserAux As ADODB.Recordset<br>
<br>
Set RsUserAux = CreateObject(&quot;ADODB.Recordset&quot;)<br>
<br>
<br>
<br>
strSQL = &quot;SELECT * FROM Department ORDER BY d_id;&quot;<br>
<br>
<br>
RsUserAux.Open strSQL, CnCalender, adOpenKeyset, adLockOptimistic, adCmdText<br>
<br>
'Clear the combo box<br>
objDepartment.Clear<br>
<br>
RsUserAux.MoveFirst<br>
<br>
Do Until RsUserAux.EOF<br>
objDepartment.AddItem RsUserAux(&quot;d_name&quot;)<br>
objDepartment.ItemData(objDepartment.NewIndex) = RsUserAux(&quot;d_id&quot;)<br>
RsUserAux.MoveNext<br>
Loop<br>
<br>
'Set to the first Department<br>
objDepartment.ListIndex = 0<br>
<br>
RsUserAux.Close<br>
Set RsUserAux = Nothing<br>
<br>
End Sub<br>
<br>
'******************************************************<br>
<br>
<br>
'This is the routine that displays the data to the users<br>
<br>
If Not IsNull(RsTheUsers(&quot;u_dept&quot;)) Then<br>
.cboDept.ListIndex = 0<br>
Do While .cboDept.ItemData(.cboDept.ListIndex) &lt;&gt; RsTheUsers(&quot;u_dept&quot;)<br>
.cboDept.ListIndex = .cboDept.ListIndex + 1<br>
Loop<br>
End If<br>
<br>
'******************************************************<br>
<br>
'This is the routine that saves the data <br>
<br>
Sub Save_UserRecord(operation As String)<br>
<br>
With frmUsers<br>
If operation = &quot;Add&quot; Or operation = &quot;Edit&quot; Then<br>
<br>
RsTheUsers(&quot;u_id&quot;) = .txtUserFields(0)<br>
RsTheUsers(&quot;u_lname&quot;) = .txtUserFields(1)<br>
RsTheUsers(&quot;u_fname&quot;) = .txtUserFields(2)<br>
RsTheUsers(&quot;u_mi&quot;) = .txtUserFields(3)<br>
RsTheUsers(&quot;u_password&quot;) = .txtUserFields(4)<br>
<br>
If .cboDept &lt;&gt; &quot;&quot; Then RsTheUsers(&quot;u_dept&quot;) = .cboDept.ItemData(.cboDept.ListIndex)<br>
'If .cboDept &lt;&gt; &quot;&quot; Then RsTheUsers(&quot;u_dept&quot;) = RsUserAux(&quot;d_id&quot;)<br>
<br>
End If<br>
End With<br>
RsTheUsers.Update<br>
<br>
Call ShowUsersFields<br>
<br>
<br>
End Sub<br>
<br>

 
As far as I'm aware - ItemData is always an integer - sorry.<br>
<br>
-ml<br>
<p>Mike Lacey<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
ItemData is always an integer. You could append the id code to the cbodescription with a preceeding character (like ~) which would let you parse the id by calling a routine to divide the combined description back into two pieces. I have done something similar and appended several spaces before the special character so that the appended information does not even appear within the specified width of the combo box.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top