Link to home
Start Free TrialLog in
Avatar of ADawn
ADawn

asked on

Add (NONE) to Combo List

Hello,

VB6 (sp5), ADO, Access 97

I want the user to have the option of selecting an item called (No Notification) or (None) if one of the supervisor's names does not appear in the combo box.


' Fill the Supervisor Combo Box
   
sSqlSupvr = "Select tbl_ApplicationUsers.UserLName, " _
    & "tbl_ApplicationUsers.UserFName, " _
    & "tbl_ApplicationUsers.UserDepartment " _
    & "From tbl_ApplicationUsers " _
    & "WHERE(tbl_ApplicationUsers.UserSupervisor = True) " _
    & "ORDER BY UserLName ASC;"

    rst.CursorLocation = adUseClient
    rst.Open sSqlSupvr, App_Conn, adOpenKeyset, adLockOptimistic

    Do While Not rst.EOF
      strSupvrName = rst("UserLName") & ", " & rst("UserFName")
      Me.cboSupvr.AddItem strSupvrName
      rst.MoveNext
    Loop

Thanks,

-ADawn
ASKER CERTIFIED SOLUTION
Avatar of Dave_Greene
Dave_Greene

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Me.cboSupvr.AddItem "(NONE)"
Do While Not rst.EOF
     strSupvrName = rst("UserLName") & ", " & rst("UserFName")
     Me.cboSupvr.AddItem strSupvrName
     rst.MoveNext
Loop
Avatar of nomulap
nomulap

Use This code

>>     dim blnSupFound as boolean
>>     dim strSupNameLookingFor as string          


>>                     'Set the the supervisor name you are looking for
>>                    strSupNameLookingFor  = "Supervisor1"    

' Fill the Supervisor Combo Box  
                    sSqlSupvr = "Select tbl_ApplicationUsers.UserLName, " _
                      & "tbl_ApplicationUsers.UserFName, " _
                      & "tbl_ApplicationUsers.UserDepartment " _
                      & "From tbl_ApplicationUsers " _
                      & "WHERE(tbl_ApplicationUsers.UserSupervisor = True) " _
                      & "ORDER BY UserLName ASC;"

                      rst.CursorLocation = adUseClient
                      rst.Open sSqlSupvr, App_Conn, adOpenKeyset, adLockOptimistic                  

                      Do While Not rst.EOF
                        strSupvrName = rst("UserLName") & ", " & rst("UserFName")
                        Me.cboSupvr.AddItem strSupvrName
>>                        if strSupNameLookingFor = strSupvrName then
>>                              blnSupFound = True
>>                        End if
                        rst.MoveNext
                      Loop
>>                      If blnSupFound = False then
>>                              Me.cboSupvr.AddItem "NONE"
>>                      End if
You can do it in your SQL too ...

Select tbl_ApplicationUsers.UserLName, " _
   & "tbl_ApplicationUsers.UserFName, " _
   & "tbl_ApplicationUsers.UserDepartment " _
   & "From tbl_ApplicationUsers " _
   & "WHERE(tbl_ApplicationUsers.UserSupervisor = True) " _
   & "ORDER BY UserLName ASC;"

UNION

SELECT TOP 1 'None', '','' FROM tbl_ApplicationUsers