×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Combo Box changing the ItemData or NewIndex property to accept text

Combo Box changing the ItemData or NewIndex property to accept text

Combo Box changing the ItemData or NewIndex property to accept text

(OP)
*database combo box question*

These routines works fine if RsUserAux("d_id") is an integer
all the time.

May problem is if RsUserAux("d_id") is a string containing
any value like 12, a, d, 4, 23333.8888, hi, etc, etc.
How can I modify may routines to look at the RsUserAux("d_id") values that I mentioned.

This routine creates the combo box

'******************************************************
Sub CreateDepartmentCombo(ByRef objDepartment As ComboBox)

Dim RsUserAux As ADODB.Recordset

Set RsUserAux = CreateObject("ADODB.Recordset")



strSQL = "SELECT * FROM Department ORDER BY d_id;"


RsUserAux.Open strSQL, CnCalender, adOpenKeyset, adLockOptimistic, adCmdText

'Clear the combo box
objDepartment.Clear

RsUserAux.MoveFirst

Do Until RsUserAux.EOF
objDepartment.AddItem RsUserAux("d_name")
objDepartment.ItemData(objDepartment.NewIndex) = RsUserAux("d_id")
RsUserAux.MoveNext
Loop

'Set to the first Department
objDepartment.ListIndex = 0

RsUserAux.Close
Set RsUserAux = Nothing

End Sub

'******************************************************


'This is the routine that displays the data to the users

If Not IsNull(RsTheUsers("u_dept")) Then
.cboDept.ListIndex = 0
Do While .cboDept.ItemData(.cboDept.ListIndex) <> RsTheUsers("u_dept")
.cboDept.ListIndex = .cboDept.ListIndex + 1
Loop
End If

'******************************************************

'This is the routine that saves the data

Sub Save_UserRecord(operation As String)

With frmUsers
If operation = "Add" Or operation = "Edit" Then

RsTheUsers("u_id") = .txtUserFields(0)
RsTheUsers("u_lname") = .txtUserFields(1)
RsTheUsers("u_fname") = .txtUserFields(2)
RsTheUsers("u_mi") = .txtUserFields(3)
RsTheUsers("u_password") = .txtUserFields(4)

If .cboDept <> "" Then RsTheUsers("u_dept") = .cboDept.ItemData(.cboDept.ListIndex)
'If .cboDept <> "" Then RsTheUsers("u_dept") = RsUserAux("d_id")

End If
End With
RsTheUsers.Update

Call ShowUsersFields


End Sub

RE: Combo Box changing the ItemData or NewIndex property to accept text

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close