Solved

how to fill combo with recordset avoiding nulls?

Posted on 1998-09-17
5
175 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
vb6 programatically bring window to front 8 52
DIR issue 7 46
VBA color chart bars 12 65
vb6 connector to mongodb 2 26
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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

708 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