Displaying data in a subform via Recordset...

  • Thread starter Thread starter Joao
  • Start date Start date
J

Joao

Trying to pass a SQL expression to a subform. The SQL expression returns
records using Query view in access, but using this...
....
SQLString = "SELECT * FROM Processos"
funcRunSQL SQLString
....

Public Function funcRunSQL(strCmdSQL As String)

Set BD = CurrentDb

Set rstSQL = BD.OpenRecordset( _
strCmdSQL, dbOpenDynaset)

'Name of the subform
subfrmConcDU.Form.RecordSource = strCmdSQL

rstSQL.Close
BD.Close

I get nothing! Why?
 
Opening a recordset is not necessary. All you need is:

Me.subfrmConcDU.Form.RecordSource = "SELECT * FROM Processos;"
 
Thank you Klatuu, but I get no records whatsoever. Maybe something in subform
that's not right?
 
How are the form and subform related?
In other words, do you have the Link Master Field(s) and Link Child Field(s)
properties of the subform control set to fields in you form's record source
and subform's recordsource set properly?
 
How is the form's recordset related to the subform's recordset?

Try pasting your SQL into a query in the query designer in SQL view and see
what it returns.
 
Okay that anwered one of my questions.
Now, in the subform control on the main form there are two properties, Link
Master Field(s) and Link Child Field(s)
These are used to relate the child records in the subform to the parent
record in the main form. The Link Master Field(s) property should have the
name of the field or fields you use in the main form's recordset to relate to
records in the subform's recordset. The Link Child Field(s) property should
have the name of the field or fields in the subform's recordset you use to
relate to the record in the main form. If these are not set correctly, you
may not get any records in the subform.
 
Back
Top