here is a new thread for me..;)

I have some duplicate records on table, fields are ecode, ename, desig.
some records in ename are same, BUT ecode are different, i just want to do that when i click

ename on datacombo it should gives msg for ecode. e.g

ecode ename
101 yasir
102 raqib
103 nabil
105 yasir
109 hamaz
106 raqib


in datacombo its show all records, when i click yasir, it show 101, when i click next in

last yasir it again show 101, it should show 105. same as raqib, it show 102, and last

click on raqib it again show 102 not 106

PLEASE REPLY ME SOON..
THANKS

YASIR FARID

Dani AI

Generated

— the root cause is that each click re-runs the same search and always returns the first match. and are pointing in the right direction: keep the set of matching ecodes in memory and iterate it rather than re-searching from scratch on every click. Two practical patterns: 1) load all ecodes for the chosen name into a form-level collection/array and advance an index on each "next" action; 2) change the combo display so each entry is unique (for example show "ecode - ename" or bind the ecode as the combo value).

A minimal VB6/ADO pattern (store at form scope: codes As Collection, currentIndex As Long, currentName As String):

' Combo_Click: load matches
Set codes = New Collection
currentName = Combo1.Text
Set rs = New ADODB.Recordset
rs.Open "SELECT ecode FROM employee WHERE ename = '" & Replace(currentName,"'","''") & "' ORDER BY ecode", cn, adOpenForwardOnly, adLockReadOnly
Do Until rs.EOF
  codes.Add CStr(rs!ecode)
  rs.MoveNext
Loop
rs.Close
If codes.Count > 0 Then
  currentIndex = 1
  Text1.Text = codes(currentIndex)
End If

' Next button: advance and wrap
currentIndex = currentIndex + 1
If currentIndex > codes.Count Then currentIndex = 1
Text1.Text = codes(currentIndex)

Notes: keep codes and currentIndex as form-level variables so state persists between events; reset them when the selected name changes. Escape single quotes in names (shown above). Do not rely on RecordCount with forward-only cursors — build the collection by looping. If immediate clarity is preferred, put both ecode and ename in the combo display or present ecodes in a separate listbox so the user explicitly picks which code they want.

Recommended Answers

All 2 Replies

Hi,

System will not understand that, u have to code for it, Keep a Boolean Variable and Open a new recordset and have another button for "FindNext"..

Regards
Veena

I think it is the code inside the next click that is bringing the same record again. Inside the next click, what presently searching is the first occurance of your Yasir, or whatever name. Instead of it, your datacombo should move to the next occurance of yasir in the combo.

regards

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.