DoCmd.FindRecord...How to use to match a field value

  • Thread starter trekgoes2malaysia
  • Start date
T

trekgoes2malaysia

When I open a form, I would like Access to go to a specified record
that meets the criteria in a certain field using the
'DoCmd.FindRecord' command in VBA. Unfortunately I have not had much
success this way. Can you explain how I can find a record based on
the contents of a field on the form. Below is my VBA code.

Private Sub Workouts_Click()

Dim stfilter As String
Dim stFormName As String
Dim getdateid As Integer


stFormName = "Datelog"
getdateid = Me!Workouts.Value

stfilter = "[athleteid]=" & Me![Athleteid]

DoCmd.Close, acform, Me!Workouts

DoCmd.OpenForm stFormName, , , stfilter

DoCmd.FindRecord getdateid,,,,,acAll









End Sub
 
P

Pieter Wijnen

Dim RsC As DAO.Recordset
Dim getdateid As Long ' if it's a date use: Dim getdateid As Date
'.. your code

DoCmd.OpenForm stFormName, , , stfilter
Set RsC = Forms(stFormName).RecordsetClone
RsC.FindFirst "DateID = " & getdateid
'RsC.FindFirst "DateField = #" & Format(getdateid,"yyyy-mm-dd") & "#"
If Not RsC.NoMatch Then
Me.Bookmark = RsC.BookMark
End If
Set RsC = Nothing


HtH

Pieter
 

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

Similar Threads

Default setting in a list box 3
Open form code 5
Filter Help 5
docmd.findrecord 1
Fliter 3
VBA - exporting serial letters to single documents 0
Dynamic Naming of Form Button 3
Onchange event not working 5

Top