Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Works when step-through, but not when running...WHY??? 2

Status
Not open for further replies.

perplexd

Programmer
May 9, 2002
154
US
Hi folks!

For some reason this little bit of code works when I step through with the debug toolbar, but not when I just tell it to run. Why is this and how do I make it work as it should do?

In calling sub
If InCboBox(cboDesc, cboDesc.Text) = False Then
cboDesc.Clear

If optFileCode.Value = True Then
LoadFileCodeDescs
Else
LoadPartNoDescs
End If
End If


InCboBox Function (within sep module)
Public Function InCboBox(cboBox As ComboBox, SearchItem As String) As Boolean
'If item is in cboBox then True, else False
InCboBox = False
For i = 0 To (cboBox.ListCount - 1)
If cboBox.List(i) = SearchItem Then
InCboBox = True
Exit For
End If
Next i
End Function


LoadPartNoDescs (LoadFileCodeDescs is similar) Sub LoadPartNoDescs()
'Clear current descriptions
cboDesc.Clear

Dim rs As ADODB.Recordset
Set rs = con.Execute("qryPartNoDescs")

'Load all descriptions to cboDesc
With rs
Do While Not .EOF
cboDesc.AddItem !ProdDesc
.MoveNext
Loop
End With
rs.Close
Set rs = Nothing
End Sub


 
Put DoEvents in there somewhere like this:

If InCboBox(cboDesc, cboDesc.Text) = False Then
cboDesc.Clear
DoEvents
If optFileCode.Value = True Then
LoadFileCodeDescs
Else
LoadPartNoDescs
End If
End If
DoEvents
try this and see what that does for you. ----------------
Joe
 
Its most likely a timing issue.

As you're stepping thru the code, depending on which lines are being executed, messages are sent to Windows for it to process. When you're stepping thru the code, Windows has time to process the message as they arrive, but at full speed, program execution may get ahead of Windows, thus leading to these unpredicatable results.

I think lovel811 is on the right track with the use of DoEvents - which gives Windows more time to handle queued up messages. But without knowing more about the symptoms that you're experiencing, I can't comment on where to place the DoEvents.

I also note that you are clearing the Description Combo box twice, at the top of the calling Sub, and at the top of the LoadDesc sub. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Yeah...its only clearing twice cos I've been messing about trying to get it to work!!

The symptom is quite simply that the combo box list is not updating. ie although the added item does not appear in the combo list initially, when the list is refreshed from the database the item is still not there.
 
Perhaps the issue is not in the rebuilding of the combo box, but in the updating of the database. There has been some great discussions recently on the database update lag times. See thread222-298724. I would pay particular attention to CCLINT's and strongm's posts.

It could be that you are reloading the combo box before the database update actually takes place.
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
I was completely unaware that Jet caches...though its not that surprising. I'll have a look...

Thanks
 
Thanks guys. It was the caching which was causing the problem...but I didn't know about the occasional need for DoEvents either...so I've learned something extra!

Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top