Displaying data in a subform via Recordset...

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?
 
K

Klatuu

Opening a recordset is not necessary. All you need is:

Me.subfrmConcDU.Form.RecordSource = "SELECT * FROM Processos;"
 
J

Joao

Thank you Klatuu, but I get no records whatsoever. Maybe something in subform
that's not right?
 
K

Klatuu

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?
 
K

Klatuu

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.
 
K

Klatuu

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.
 

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