Solved

how to fill combo with recordset avoiding nulls?

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

690 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