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
Solved

how to fill combo with recordset avoiding nulls?

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library 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…

808 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