How to "jump" (select/setfocus) to a specific record in a long report

senseidan

Registered User.
Local time
Today, 23:23
Joined
Jan 25, 2018
Messages
38
I have a report which contains all data within a month, grouped by days. The report is embedded in a form which contain a textbox. I need to be able "scroll" the report to a specific date, which I select/enter in the textbox. I have tried different methods like GoToRecord, FindRecord, SetFilter, SearchForRecord etc. and I think SearchForRecord is close to what I need but something is missing and I don't know what.

This is the code I use:

Dim strFind As String
strFind = Format(Me.txtCStart, "Long Date", 0, 0)
Me.Child2.SetFocus
DoCmd.SearchForRecord , , acFirst, "[DATAED By Day] = 'strFind'"
Me.Child2.Report![DATAED By Day].SetFocus
 
Since you really did not define what the issue(if any) is, I can only assume your code is not working.

Looking at your code, everything seems to be right except for the string that contains a date. When working with Access and dates, you usually have to wrap you string with hashtags, or pound signs (#)

Try this:
strFind = “#” & Format(Me.txtCStart, "Long Date", 0, 0) & “#”
 
Last edited:
use FindRecord instead:
Code:
Me.Child2.SetFocus
Me.Child2.Report![DATAED By Day].SetFocus
DoCmd.FindRecord Me.txtCStart, , , acSearchAll, True, acCurrent
 
First of all, thank you both, NauticalGent and arnelgp.
I tried your suggestions even if I had tried them before. As I anticipated, they did not work but they caused me to recreate the troublesome form from scratch and test again the code sent by arnelgp. This time everything went as it should so I realized that maybe the source of the problem comes from the fact that the original form is embedded in another form (which I did not even mention because I thought it did not matter).
To convince myself, I embedded the form that worked in a new form and suddenly its behavior became identical to the one in the original scenario: the search is done in the report (I can see that from the downward and upward movement of the scroll bar) and the target is not found in the report but in the form, more precisely in the box where the search is initiated (the text in this box is selected).
I do not have the slightest idea of ​​why this happens so any suggestion will be highly appreciated.
 

Users who are viewing this thread

Back
Top Bottom