Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to fill combo with recordset avoiding nulls?

Posted on 1998-09-17
5
Medium Priority
?
190 Views
Last Modified: 2010-04-30
I can fill a combobox with a recordset field but cannot avoid nulls and other things?
Something like this
Do While not datacontrol.recordset.eof
cboComboBox.additem datacontrol.recortset(1)
recordset.movenext
loop

Needless to say I run into null fields and record is not current. Does anyone have a routine that performs the above. I can post the exact code later (as I am not at home) that I have, but I have spent many hours trying to solve this problem.

Any help would be appreciated

Regards fred
0
Comment
Question by:gosportlad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:dabellei
ID: 1435377
Do While not datacontrol.recordset.eof
    if not isnull(datacontrol.recordset(1) then
       cboComboBox.additem datacontrol.recortset(1)
    endif
    recordset.movenext
loop

This will skip the null record...
0
 

Author Comment

by:gosportlad
ID: 1435378
Your answer works well but I was looking for something a little more generic and complete, surely someone must have done this before. What I would like to do is something like the following. I can post the code I have later when I get home, if you would like to look at it so far.

1. Check the recordset against the new or changed entry in the combobox text for existing duplicate names that I have populated the combo box with already.
2. If the combobox has a duplicate then exit the routine (therefore the record exists and there is no need to add it)
3. If the combobox does not have a duplicate, then add it to the recordset and refresh the drop down combo with the new addition.
4. Remember the entry in the combo box and keep it there. Bookmark?
5. Check for null values
Do While not datacontrol.recordset.eof
    if not isnull(datacontrol.recordset(1) then
       cboComboBox.additem datacontrol.recortset(1)
    endif
    recordset.movenext
loop

This will skip the null record...

Thank you for your help so far,

Regards Fred


0
 
LVL 14

Expert Comment

by:waty
ID: 1435379
Do as follow :

Do While not datacontrol.recordset.eof
   cboComboBox.additem datacontrol.recortset(1) & ""
   recordset.movenext
loop

or

Do While not datacontrol.recordset.eof
   if (datacontrol.recortset(1) & "") <> "" then  
       cboComboBox.additem datacontrol.recortset(1)
   End If

   recordset.movenext
loop

0
 

Author Comment

by:gosportlad
ID: 1435380
You never read my comment. I know how to fill a combo box with a set of records. What if there are no records in the recordset. What if it is a duplicate record that you are adding, how do you return to the current record in the combo box that was either added or changed.

Thanks for your suggestion.
0
 
LVL 14

Accepted Solution

by:
waty earned 200 total points
ID: 1435381
You never told about duplicates.

BTW, If no records are in the recordset, the combo will be empty.
For duplicates, do as follow :

' *** Create this query
sSQL = "Select Distinct yourField From yourTable"

' *** Load the recordset using this query

cboComboBox.Clear
Do While not datacontrol.recordset.eof
   if (datacontrol.recortset("yourField") & "") <> "" then    
       cboComboBox.additem datacontrol.recortset(1)
   End If

   recordset.movenext
loop

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

604 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