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

master/subform code - cross referencing fields 1

Status
Not open for further replies.

nexus

Programmer
Jun 16, 1999
28
0
0
CA
need some help with a master/subform issue.<br>
<br>
I need to generate an SQL query to populate a combo box in the subform based on a field on the master form. I'm not sure if I should be doing this in an event, or a function. My other problem is limiting the number of records possible based on a field. in the master form, a field will allow the user to select how many records he needs, then in the subform, I have to limit how many records can be entered. TIA...
 
Put this code in the &quot;After_update&quot; event of your field<br>
Open forn in design view<br>
Double click on the field<br>
then click the &quot;Data&quot; TAB (at opt of properties)<br>
then llok for After update<br>
Click in that box click down arrow<br>
Click &quot;Event Procedure&quot;<br>
Click &quot;3 dots&quot; button<br>
Paste this in there<br>
--------------------------<br>
Dim db As Database, rst As Recordset, SQL As String<br>
Set db = CurrentDb<br>
' SQL string.<br>
SQL = &quot;SELECT Myfield From Mytable Where MyField = &quot; & Forms![frm-Order Parts]![OrderParts subform1].Form![Textbox] & &quot;';&quot;<br>
me!Combo1.Recordsource = SQL<br>
me!Combo1.Requery<br>
---------------------------<br>
Change the names of Myfield to the field you want to serach in and MyTable to your table<br>
And [Textbox] to the field on your main form.<br>
this will get you started on the SQL for the combo<br>
<br>
AS far as limiting the number of records to enter<br>
you could create that number of records and have a filed as a place holder say some kind of counter.<br>
Lets say you are adding 10 records in For Next loop add 10 records and have a field called &quot;Counter1&quot;. Have 1 through 10 so the first record has number 1 second record has number 2 and so on...<br>
Then tell them to just add that many nad no more.<br>
Or If you try to put those 10 records in a recordset so you only see 10 and no more. That might work too.<br>
<br>
OK <p> DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top