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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Box

Status
Not open for further replies.

BF

Programmer
Feb 13, 2000
10
CA
I have a table with two fields. One field is named &quot;Rank&quot; and the other is &quot;LastName&quot;. Each Lastname is given a rank of 1 - 13. When I pull up a record on my form from this table, I would like to populate a combo box (same form) with all Lastnames greater than the rank given to the Lastname that is current on the form. <br>
<br>
For example: <br>
<br>
LastName: Brown <br>
Rank: 5<br>
<br>
This would generate a list in my combo box with all Lastnames greater than 5. <br>
<br>
Thanks Roger
 
This can be done using VBA code and passing an SQL statement to your table of names.<br>
<br>
In the forms &quot;On_Current&quot; event put the following code.<br>
<br>
If you open the forms &quot;ALL&quot; Properties and look down the list you will see Events. On_Load, On_click, On_Current etc.etc.<br>
Put and &quot;Event Procedure&quot; in the On_Current <br>
--------------------------------------------------------------<br>
Dim db as database, rst as recordset, SQL as string<br>
Set db = CurrentDb<br>
' SQL string.<br>
SQL = &quot;SELECT * FROM YourTable WHERE LastName = &quot;& Me!Lastname<br>
Set rst = db.OpenRecordset(SQL)<br>
Me!Rank = rst!Rank<br>
Rst.close<br>
Db.close<br>
----------------------------------------------------------<br>
<br>
Now as you move through the records it will trip the On_current event and run this code.<br>
And instantly put &quot;RANK&quot; in the field on your form.<br>
<br>
<br>
<br>
<p> DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br>
 
Dim db as database, rst as recordset, SQL as string<br>
dim txtRank as textbox, intR as integer<br>
Set db = CurrentDb<br>
set txtRank = me.name of textbox on form<br>
intR = txtRank.value<br>
SQL = &quot;SELECT * FROM YourTable WHERE [rank] =&gt;&quot; intR<br>
<br>
<br>
<br>
this will limit the records to those where rank is greater or equal to Rank<br>
<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top