Solved

how to fill combo with recordset avoiding nulls?

Posted on 1998-09-17
5
176 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
  • 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 100 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Use Multiple Forms 4 48
VBA : retain and exclude values based on a config sheet and multiple parameters 5 52
Copy a row 12 57
using web browser with BING 40 110
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

932 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