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

senseidan

Registered User.
Local time
Today, 08:10
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
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 03:10
Joined
Apr 27, 2015
Messages
6,331
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:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:10
Joined
May 7, 2009
Messages
19,233
use FindRecord instead:
Code:
Me.Child2.SetFocus
Me.Child2.Report![DATAED By Day].SetFocus
DoCmd.FindRecord Me.txtCStart, , , acSearchAll, True, acCurrent
 

senseidan

Registered User.
Local time
Today, 08:10
Joined
Jan 25, 2018
Messages
38
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

Top Bottom