I have an Access client to SQL Server that uses a tabbed form with several subforms. Basically, a product is selected on the main form, and then the tabs give access to edit/insert different properties of the product (options, colors, styes, etc) stored in different related tables. Each subform uses it's own record source, but is synced to the main form on a product number.
So, I have combo box in a subform, call it "Options", that I want to populate with data from a query that uses the product number in the "where" clause. That's what I need to do. How I did it was to use the OnCurrent event of the Options subform to set the RowSource equal to an SQL string. That works, but...the OnCurrent event fires every time a new product is selected in the main form, whether or not the Options subform form has the focus. Then it fires again when Options get the focus. And then, since Options uses a data sheet layout, it fires for every record selected, even though the record source doesn't need to change.
Although this works, it's a lot of unnecessary data being shot back and forth to a (very) remote SQL Server. So, is there another event to use that works for the whole subform, ideally just firing once, and not for each record within the subform? I tried Got Focus, but that never fired. And the Open and Load events don't fire when a new product is selected (of course). Or maybe there is another place I should be setting the options subform record source?
Here's the event code:
Private Sub Form_Current()
Dim sql As String
sql = "SELECT O.[OptionID], O.[Caption] FROM ProductOptions AS O WHERE o.[OptionTypeID] in (1,2,8,9) AND o.ProductNumber = "
sql = sql & "'" & Nz(Forms![products main form]!ProductNumber, "99test") & "'"
oidSelect1.RowSource = sql
End Sub
Thanks for any help.
Jim