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

Subform & SQL

Status
Not open for further replies.

BF

Programmer
Feb 13, 2000
10
CA
I have a subform on my main form. I would like for an SQL statement to run each time I move to a new record on the main form. The SQL statement will update the subform from a table with each record change. Can someone give me a quick example on how to accomplish this?<br>
<br>
Thanks <p>BF<br><a href=mailto:g43@tc3net.com>g43@tc3net.com</a><br><a href= > </a><br>
 
There are a lot of unknowns here not sure where your data is coming from<br>
<br>
Dim db as database, rst as recordset, SQL as string<br>
Dim MySQL As String<br>
<br>
Set db = CurrentDb<br>
' SQL string.<br>
SQL = &quot;SELECT * FROM YourTable WHERE SomeField = &quot; & SomeValue<br>
Set rst = db.OpenRecordset(SQL) <br>
<br>
' Initialize SELECT statement.<br>
MySQL = &quot;SELECT * FROM OtherTable WHERE SomeField = &quot; & rst.fields(&quot;myfield) '&lt; Finish this based on What you are doing<br>
' set record source to Subform <br>
Me![YOURsubform].Form.RecordSource = MySQL <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