?
Solved

adding item to a combo control while looping thru a recordset

Posted on 2003-03-30
13
Medium Priority
?
525 Views
Last Modified: 2013-12-25
hi,
i'm working on a VB app, that talks with an Access XP DB. i have upgraded VB 6.0 with SP5.

in my app, i'm trying to add items to a combo control while trying to loop thru a recordset.

the following is a piece of my code. adoPatientHistory is a an ADO controlm with a 'adOpenStatic' cursor type.
******************************************************
Do Until adoPatientHistory.Recordset.EOF

cmbExamDate.AddItem adoPatientHistory.Recordset.Fields("Examination_Date")

adoPatientHistory.Recordset.MoveNext

Loop
***************************************************

i hit an 'Operation Cancelled (80040e4e)' error at the 'MoveNext' method. I dunno if this is a known bug in the recordsets or something else. coz, i can use the same recordset field, as a 'WHERE' clause while using a 'SELECT', and it works without a hitch.

any help in fixing this bug or circumnavigating it would be great.
thanx
hifzur
0
Comment
Question by:inquisitive2003
[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
13 Comments
 
LVL 4

Expert Comment

by:bistrica
ID: 8234768
Do Until adoPatientHistory.Recordset.EOF

with previous you will loop until eof, so

this: adoPatientHistory.Recordset.MoveNext will hit eof before until.

Try:

Do while not adoPatientHistory.Recordset.EOF








0
 

Author Comment

by:inquisitive2003
ID: 8235440
bistrica,

thanx for the post.

i still hit the same error. i dont think its the EOF issue at all. coz, this error is generated the very first time control goes to the adoPatientHistory.RecordSet.MoveNext line, while i still have atleast 2 rows to be looped through.

thanx
0
 
LVL 1

Expert Comment

by:ayufans
ID: 8236375
Try the following :

If adopatienthistory.RecordCount > 0 Then
    adopatienthistory.MoveFirst
    While Not adopatienthistory.EOF
        rekord = adopatienthistory.field("Examination_Date")
        Combo1.AddItem (rekord)
        adopatienthistory.MoveNext
    Wend
End If

Good Luck
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 8236379
What is in your cmbExamDate_Click or cmbExamDate_Change (depending on the .Style property) event that is causing this problem?

Anthony
0
 

Author Comment

by:inquisitive2003
ID: 8239477
hi all,
thanx for the posts. Anthony, the piece of code that i posted is in my form load, and not in the cmbExamDate_Click or cmbExamDate_Change event at all.

But to spare u guys some more torture, i've actually found a way to circumnavigate the problem with .AddItem from a recordset.

i assign the value from the recordset to the list item

for instance when i do...

cmbExamDate.List(i) = adoPatientHistory.Recordset.Fields("Examination_Date")

it works, perfectly without complaining. that is,the subsequent MoveNext method works without throwing the run time error.

Now why would it have a problem if i use the AddItem method of the Combo List control, i've no clue. anybody has any idea?

0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 8239772
>> the piece of code that i posted is in my form load, and not in the cmbExamDate_Click or cmbExamDate_Change event at all.<<
I realized that.  My point was that there probably is code in your cmbExamDate_Click or cmbExamDate_Change events that is causing this.  It would also explain why your work around does not cause this problem.

The only other possibility that I can think of, is that you are using (God forbid) the ADO Data Control.  If that is the case, I have no idea, as I have never used it, nor do I intend to.  It is way too much trouble.

Anthony

0
 

Author Comment

by:inquisitive2003
ID: 8243429
tony,

well, in that case, no i didnt have any code in any event for the cmbExamDate combo list.

y do u consider ADO Data Control to be too much trouble? Yes indeed, i am using ADO Data Control. u mean its trouble during development, or trouble while deployment or post installation?

thanx
0
 

Expert Comment

by:simon780
ID: 8243430
Why don't you use a DataCombo Control??
Set DataSource = Your ADO Conrol
Set rowsource = Your Database Field

anyway when I add the records to Combo box using loop, I did not get the problem you have mentioned

Good Luck!!
0
 

Author Comment

by:inquisitive2003
ID: 8243880
simon,

i can use an ADO Control as the data source for a DataCombo Control??? wow, i dindt know that. thanx for the tip.

hifz
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 8246189
Yes, I think it is too much trouble during development.  You will find that this is the case in any app that has a certain amount of complexity.  But the only way you are probably going to convince yourself of this is to use it in one app.  Most of us here have done that once.  In my case it was with the DAO Data Control some years ago.

I wish you luck,

Anthony
0
 
LVL 1

Expert Comment

by:b612_forever
ID: 8250631
I think ayunfans way should work since a have do the same thing for so many time in my work.

Anyway, you may try this:
If adoPatientHistory.Recordset.RecordCount <> 0 Then
    adoPatientHistory.Recordset.MoveFirst
    Do While Not adoPatientHistory.Recordset.EOF

        cmbExamDate.AddItem(adoPatientHistory.Recordset.Fields("Examination_Date"))
        adoPatientHistory.Recordset.MoveNext

    Loop
End If
0
 
LVL 1

Accepted Solution

by:
Balshe earned 150 total points
ID: 8362116
Try this

if adoPatientHistory.recordcount>0 then adoPatientHistory.movefirst

Do while not adoPatientHistory.Recordset.EOF

cmbExamDate.AddItem adoPatientHistory.Recordset.Fields("Examination_Date").value

adoPatientHistory.Recordset.MoveNext

Loop
0
 

Author Comment

by:inquisitive2003
ID: 8365088
thanx for all your support!!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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.
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…
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

800 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