I will give you an example of how I do this.
This is done with ADO.
First, I have this function which returns a recordset (readonly)
Now, lets say I have a DataGrid control on my form and a text box and a command button. When the user clicks the command button, it executes the sql statement entered into the text box.
'opens an ado read only recordset
Public Function OpenRSro(sql As String) As ADODB.Recordset
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.Open sql, cn, adOpenForwardOnly
Set OpenRSro = rst
So I would have some code like this:
This is just a simplified version, but you get the idea. You have to set the datasource property = to the recordset returned, and it does have to be done with set.
Private Sub Command1_Click()
Set DataGrid1.DataSource = OperRSro(Text1.Text)