Access Subform Datasheet Only Returning 1 Result

南楼画角 提交于 2019-12-02 16:31:28

问题


I know this question has been asked multiple times in some form or fashion, but I'm not been able to find a solution that works and it's driving me crazy. I'm creating a search form in Access that executes a select query via VBA to find data that is in a table. So far this has been pretty straight forward, the query works, and the form returns results. The issue is that I'm using a subform to return/display the results and it is only returning one result at a time.

I used the setup wizard to add the subform to the main form and I linked the two forms during that process. I have the subform being displayed as a datasheet, but even if I change it to a "continuous form" it still just returns one record at a time. I have my subform's Record Source set as my Select query (Select * From tbl_Search) , and I've set the Record Source for my main form to just about anything I can think of (Select query, table, nothing...).

I know there has to be a way to return all the records in one datasheet without having to continuously click the next arrow, but I have yet to figure out what that way is.

Since this isn't an issue with the code per se, I wasn't sure what kind of images or code blocks might be necessary to answer this question, so i tried to be as descriptive as possible. If there is a chunk of code or screenshot that you need to help answer this question, just let me know.


回答1:


Your main form should be unbound. Create a search query and set it as the subform's recordsource. You can pass the main form's fields as parameters to the query, for example:

PARAMETERS [Forms]![YourMainForm]![YourTextField] Text (255);
SELECT *
FROM YourTableName
WHERE ((([FieldName)=[Forms]![YourMainForm]![YourTextField]));

The only thing you have to do when running a search is to .Requery the subform.

Me.SubformName.Form.Requery


来源:https://stackoverflow.com/questions/47147117/access-subform-datasheet-only-returning-1-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!