In MS Access i have created a database which has a main form and a sub form and are in a one to many relationship, then i have created a search box on my main form which i should be able to search base on both, the main and sub forms' fields which i can do it. Now when ever i am searching the form shows the searched record but the problems is that non of the main forms' controls (save, new, delete, next, previous and etc) on my main form is working. It would be my pleasure to guide me on this issue...Thanks,
1 Answers
Re Navigation
Based on the method you are using to search, you will not be able to navigate backward and forward. If you do want to navigate backward and forward, you will need to specify a search range. For example, instead of searching for a SINGLE record with ID 123, you will need to search for a RANGE of records, i.e., between ID 123 and ID 234.
Re Saving
You do not need to explicitly save records on bound forms (forms that are tied directly to a recordsource). You just change the data, and then move on. Once you move on, your data will be saved - as long as table constraints are not violated.
Re Search
When you create a main form/sub form in Access, the 2 forms are linked through the Child/Master properties. So, if you are searching for a specific record in the main form, you generally don't need to worry about filtering the sub form as well. Using a method similar to what you have in the comments it would be:
dim qry As String
qry = "select parenttbl.* from parenttbl where parenttbl.id=" & Me.mysearchbox.text &";"
Me.RecordSource = qry
By joining the child table in your original code, you may have confused Access' ability to save, but I doubt it. I didn't test it, but I don't think you need to turn the filteron property to true after changing the recordsource. See how filteron is used in this post by Allen Browne http://allenbrowne.com/ser-28.html
Re FilterOn With that said, you can probably tweak his use of the filteron property to "search" for your desired record, then you may be able to turn the filteron property to False and then navigate backward and forward in your recordset. I didn't test it though.
EDIT: Here is an example when to set the FilterOn property to false:
Me.FilterOn = False
DoCmd.GoToRecord , , acNext
For this to work, you will need to specify the ORDER BY
clause in the SQL query that your main form is bound to. Otherwise you may not navigate backward and forward the way you would expect.