Understand, let me break the code down for you, then we can try a couple
of
things to see what the problem is.
'The With End With structure says that the properties and methods
referenced
between the With and End With belong to the specified object. They begin
with a period.
It does two things. First, it is shorthand so you don't have to type in
the
object reference repeatedly and second, there is a bit of a performance
gain
because the reference only has to be established one time using with;
otherwise, it has to establish the reference for each occurance of the
object.
With Me.RecordsetClone
'The FindFirst method looks for a record that matches the criteria. The
criteria is coded as if it were an SQL WHERE clause without the word
Where.
The data types have to be correct. In the example, it is expecting the
CaseID field in the form's record source to be a numer field. The control
name CaseNumberPicker I just made up. It needs to be the control where
you
enter the case number.
.FindFirst "[CaseID] = " & Me.CaseNamePicker
If CaseID is a text field, the correct syntax would be:
.FindFirst "[CaseID] = """ & Me.CaseNamePicker & """"
(That is 3 leading double quotes and 4 trailing)
If Not .NoMatch Then
The NoMatch property will return False if a matching record is found and
True if no matching record is found. This test is put in because if you
tried to move to a record you would get an error because these is no
matching
record.
Me.Bookmark = .Bookmark
This is where the selected record is made the current record. The
Bookmark
property points to the current record in a recordset. In this case, the
Bookmark of the RecordsetClone is the record found using the FindFirst.
The
line then makes the form's current record the same as the RecordSetClone
Bookmark.
End If
End With
Now, since nothing is happening, I suspect it is not finding a record. I
assume you have entered valid records and still had no results. First, be
sure the data types are correct and the control name is correct in the
code.
If you are still having a problem, run the code in debug mode and you can
watch each line execute and you can see the values in all your controls
and
variables.
Let me know if this helps, please. If you need more help, feel free to
post
back. We can make it work.
--
Dave Hargis, Microsoft Access MVP
LA Lawyer said:
Nothing happens. There is no error message.
In reviewing your code, it tells Access to find the record that first
matches the CaseID, but I don't see any code to tell Access what to do
when
it finds that first record. Could that be the issue?
It does if you do it correctly.
"Doesn't work" is pretty vague. Can you tell me what error you are
getting
or what is happening?
--
Dave Hargis, Microsoft Access MVP
:
This doesn't work.
When I use this, nothing happens.
Better way:
Private Sub CaseNamePicker_AfterUpdate()
With Me.RecordsetClone
.FindFirst "[CaseID] = " & Me.CaseNamePicker
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
End Sub
--
Dave Hargis, Microsoft Access MVP
:
This should be a newbie question but I seem to be suffering from
brain
lock.
I have an active form (CasesForm) with a List Box called
CaseNamePicker.
The row source for the list box is the CaseID, which is the key
field
for
the Cases table which is the source for the table.
I have tried this, but it doesn't work (is that because this form
is
already
open?):
DoCmd.GoToRecord acDataForm, "CasesForm", acGoTo, CaseNamePicker
This does work, but takes a long time AND obviously doesn't let me
go
between records:
Form.Filter = "CaseID =" & CaseNamePicker
Form.FilterOn = True
What is the fix? This has got to the most obvious thing!