SELECT statement using VBA? (1 Viewer)

noidentity29

New member
Local time
Yesterday, 20:39
Joined
Dec 14, 2009
Messages
2
I have spent a little more time than I would like to admit trying to get Access to select data from a table. The 'FindRecord' functionality is not working correctly. Access is pulling back all of the data and then filtering it. I need to optimize this and I thought it would be best to write the code myself.

The DoCmd.RunSQL only runs Actioin commands (Insert, Update, etc). I tried the DoCmd.OpenSQL and it opened a spreadsheet. I need to return the dataset to a form just as the default behavior of 'FindRecord' does.

Is this possible? How should I approach this?
 

ajetrumpet

Banned
Local time
Yesterday, 21:39
Joined
Jun 22, 2007
Messages
5,638
maybe set the recordsource of the form to the query or statement you want, then open the form?
 

Zaeed

Registered Annoyance
Local time
Today, 12:39
Joined
Dec 12, 2007
Messages
383
You use the docmd.runsql when you want to execute a sql command, such as Delete (Delete button on form for example). The
The Select function is for gathering a set of records based on certain criteria, and then using it as the basis of a form or report, such as building a report showing people with Surname of 'Jones'.

As Adam said, set the recordsource to your select statement..

On your load method something like this would work
Me.RecordSource = "SELECT * FROM myTable"
 

Users who are viewing this thread

Top Bottom