*database combo box question*<br>
<br>
These routines works fine if RsUserAux("d_id" is an integer<br>
all the time.<br>
<br>
May problem is if RsUserAux("d_id" 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("d_id" 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("ADODB.Recordset"<br>
<br>
<br>
<br>
strSQL = "SELECT * FROM Department ORDER BY d_id;"<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("d_name"<br>
objDepartment.ItemData(objDepartment.NewIndex) = RsUserAux("d_id"<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("u_dept") Then<br>
.cboDept.ListIndex = 0<br>
Do While .cboDept.ItemData(.cboDept.ListIndex) <> RsTheUsers("u_dept"<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 = "Add" Or operation = "Edit" Then<br>
<br>
RsTheUsers("u_id" = .txtUserFields(0)<br>
RsTheUsers("u_lname" = .txtUserFields(1)<br>
RsTheUsers("u_fname" = .txtUserFields(2)<br>
RsTheUsers("u_mi" = .txtUserFields(3)<br>
RsTheUsers("u_password" = .txtUserFields(4)<br>
<br>
If .cboDept <> "" Then RsTheUsers("u_dept" = .cboDept.ItemData(.cboDept.ListIndex)<br>
'If .cboDept <> "" Then RsTheUsers("u_dept" = RsUserAux("d_id"<br>
<br>
End If<br>
End With<br>
RsTheUsers.Update<br>
<br>
Call ShowUsersFields<br>
<br>
<br>
End Sub<br>
<br>
<br>
These routines works fine if RsUserAux("d_id" is an integer<br>
all the time.<br>
<br>
May problem is if RsUserAux("d_id" 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("d_id" 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("ADODB.Recordset"<br>
<br>
<br>
<br>
strSQL = "SELECT * FROM Department ORDER BY d_id;"<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("d_name"<br>
objDepartment.ItemData(objDepartment.NewIndex) = RsUserAux("d_id"<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("u_dept") Then<br>
.cboDept.ListIndex = 0<br>
Do While .cboDept.ItemData(.cboDept.ListIndex) <> RsTheUsers("u_dept"<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 = "Add" Or operation = "Edit" Then<br>
<br>
RsTheUsers("u_id" = .txtUserFields(0)<br>
RsTheUsers("u_lname" = .txtUserFields(1)<br>
RsTheUsers("u_fname" = .txtUserFields(2)<br>
RsTheUsers("u_mi" = .txtUserFields(3)<br>
RsTheUsers("u_password" = .txtUserFields(4)<br>
<br>
If .cboDept <> "" Then RsTheUsers("u_dept" = .cboDept.ItemData(.cboDept.ListIndex)<br>
'If .cboDept <> "" Then RsTheUsers("u_dept" = RsUserAux("d_id"<br>
<br>
End If<br>
End With<br>
RsTheUsers.Update<br>
<br>
Call ShowUsersFields<br>
<br>
<br>
End Sub<br>
<br>