0

I have a continuous form that i would like to populate via a sql select statement in my VBA script. I can't seem to make this work:

sel = "Select * from table1 where  a = 10;"
Set SQL = db.OpenRecordset(sel)
SQL.Requery

2 Answers 2

3

Why don't you put your select instruction in the recordsource property of the form?

Me.recordsource = "Select * from table1 where  a = 10;"

if your script is in one of the form's procedures, or

myForm.recordsource = "Select * from table1 where  a = 10;"

if your script is in an independant module

Sign up to request clarification or add additional context in comments.

Comments

1

If you want to use a Recordset instead of just setting the RecordSource (like already suggested in Philippe Grondier's answer), you can also do this:

Set Me.Recordset = db.OpenRecordset("select ...")

I must admit that setting the RecordSource is the "standard way" (especially if you already have a SQL statement and want to populate the form with that), but I still wanted to show this alternative solution.
I usually use it to populate a form with a Recordset that is returned by a function.

2 Comments

Totally right, and this is also the way I do it, though I systematically use ADODB instead of DAO recordsets.
Yes, me too (we're using Access as a SQL Server frontend)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.