Command Button To Find Specific Page

M

mmatzke

I am using command buttons in a sub form to navigate within records.

The sub form is date controlled
Command buttons move forward one day, back one day, or come back to present
day

I am stuck on the command button that brings us back to the present day

The code I am trying to use is:

Private Sub Command17_Click()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "Date()=" & Me![Date]
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

End Sub

Note: The main form is [Aspect Data], the sub where the command button is
on is [Aspect Data S1].
 
S

Steve Sanford

Hi Mark,

"Date" is a reserved word in Access and shouldn't be used for object names.
See this link for a list:

http://allenbrowne.com/AppIssueBadWord.html

You should also look up "Naming conventions" and use them on all objects.
Which is easier to determine the use: "Command17" or "btnTodays_Date"?

The main problem with the code is the FindFirst line is backwards. I
modified the code, but it is untested.

Note: I used "TheDate" in the code instead of "Date". You will need to
change "TheDate" to your field name.

'----code begin------------
Private Sub Command17_Click()
' Finds the record that matches the Today's date.
Dim rs As dao.Database
Dim strCriteria As String

strCriteria = "TheDate = #" & Date & "#"

Set rs = Me.Recordset.Clone
rs.FindFirst strCriteria

' check the NoMatch property after FindFirst
If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
End If

End Sub
'----code end----------------


HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top