Solved

Add (NONE) to Combo List

Posted on 2001-06-22
4
231 Views
Last Modified: 2010-08-05
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
0
Comment
Question by:ADawn
4 Comments
 
LVL 8

Accepted Solution

by:
Dave_Greene earned 30 total points
Comment Utility
' 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

Me.cboSupvr.AddItem "NONE"

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

Expert Comment

by:TimCottee
Comment Utility
Me.cboSupvr.AddItem "(NONE)"
Do While Not rst.EOF
     strSupvrName = rst("UserLName") & ", " & rst("UserFName")
     Me.cboSupvr.AddItem strSupvrName
     rst.MoveNext
Loop
0
 

Expert Comment

by:nomulap
Comment Utility
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
0
 
LVL 4

Expert Comment

by:vindevogel
Comment Utility
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
   
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now