Passing a value to a query in a subform

D

Dan Neely

I have a form with a query that requires a value to be provided for a
WHERE clause. I can open the form on it's own and enter the desired
value into a popup dialog without problem. But if I drag that form
onto a second instead of getting a popup to enter the value access03
crashes.

How can I prevent the crash from happening and pass the value for the
query from the main form automatically.
 
D

Dan Neely

I have a form with a query that requires a value to be provided for a
WHERE clause. I can open the form on it's own and enter the desired
value into a popup dialog without problem. But if I drag that form
onto a second instead of getting a popup to enter the value access03
crashes.

How can I prevent the crash from happening and pass the value for the
query from the main form automatically.

I've managed to work around this by making the child form unbound and
running query in the parents OnCurrent event to generate a record set,
but would still like to know if there's a way to do this on a bound
form.
 
H

Harry

Hi Dan,

For me it is not the best solution to alter the query at OnCurrent event.
Because this procedure is triggered every time an action is performed,
including actions not in relation to your subform.

What I have done is indeed create an unbound child form and alter the query
while doing some action (like pressing a form button, combobox whatever) the
recordsourde for the subform changes and the new data is displayed.

what you could do fe.

create on the master form a textbox named TAGID
within the code
Option Compare Database
Dim sSQL, sSQLField, stDocname As String

Private Sub BtnPC1_Click()
Me.TAGID = Me.BtnPC1.TAG
QCONTENTPC
End Sub

Function QCONTENTPC()
sSQLField = "(((Software." & TAGID & ") = Yes))"
sSQL = " SELECT Software.*, Disc.DiscName" & _
" FROM Software" & _
" INNER JOIN Disc ON Software.DiscID = Disc.DiscID" & _
" WHERE" & sSQLField & _
" ORDER BY Software.ProgramName;"
CurrentDb.QueryDefs("Q-ContentPC").SQL = sSQL
Me.PC_Content_subform.Form.RecordSource = sSQL
end function.

To use this for a bound form is more or less equal.
first you need to open the form, and secondly you can define the
recordsource for that form.
fe:
DoCmd.OpenForm "BoundForm"
Forms!BoundForm!.Form.RecordSource = sSQL

good luck
Harry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top