Binding a recordset to a form programmatically

S

SUB

hi all,

Anybody know how to this?? I create a recordset which
allows the use of SQL, but then I need to force a form to
use this data (Bind it to the form).

Dim cmd1 As ADODB.Command
Dim rst1 As ADODB.Recordset
Set cmd1 = New ADODB.Command
With cmd1
.ActiveConnection = CurrentProject.Connection
.CommandText = "SELECT * FROM [mytable]"
End With
Set rst1 = cmd1.Execute

This opens a recordset, how can I then set bind this to
either a new or existing form???

cheers in advance for assistance

SUB
 
N

Neil

Hi,

You dont even have to do that. You can use SQL in a forms RecordSource
property. So you could use the following in the forms On Load event for
example.

Private Sub Form_Load()

Dim strSQL As String

' Build the SQL string
strSQL = "SELECT * FROM [mytable]"

' Assign this to the forms RecordSource and requery
Me.RecordSource = strSQL
Me.Requery

End Sub

Hope this helps,

Neil.
 
S

SUB

thats spot...

my god, I was going the long way round..

cheers, SUB

8O)


-----Original Message-----
Hi,

You dont even have to do that. You can use SQL in a forms RecordSource
property. So you could use the following in the forms On Load event for
example.

Private Sub Form_Load()

Dim strSQL As String

' Build the SQL string
strSQL = "SELECT * FROM [mytable]"

' Assign this to the forms RecordSource and requery
Me.RecordSource = strSQL
Me.Requery

End Sub

Hope this helps,

Neil.

hi all,

Anybody know how to this?? I create a recordset which
allows the use of SQL, but then I need to force a form to
use this data (Bind it to the form).

Dim cmd1 As ADODB.Command
Dim rst1 As ADODB.Recordset
Set cmd1 = New ADODB.Command
With cmd1
.ActiveConnection = CurrentProject.Connection
.CommandText = "SELECT * FROM [mytable]"
End With
Set rst1 = cmd1.Execute

This opens a recordset, how can I then set bind this to
either a new or existing form???

cheers in advance for assistance

SUB


.
 

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