Trouble with a FindFirst

  • Thread starter Thread starter Bill
  • Start date Start date
B

Bill

I have a form named TopicsHistory whose recordsource
is a simple query. TopicsHistory opens another form, "B",
that amongst its tasks is a search in TopicsHistory's
recordsource looking for a duplicate. The code below
encounters a runtime error 2465 in not being able to find
the "field" TopicsHistory, which is not a field but is the
name of the form whose recordset is the object of the
search. Is what I've coded inappropriate for what I'm
trying to accomplish?

Me![TopicsHistory].Form.Recordset.FindFirst "Topic = """ & Me.tbTopic1 &
""""
If Me![TopicsHistory].Form.Recordset.NoMatch = False Then Me.Dup1 = "Yes"

Thanks,
Bill
 
Bill said:
I have a form named TopicsHistory whose recordsource
is a simple query. TopicsHistory opens another form, "B",
that amongst its tasks is a search in TopicsHistory's
recordsource looking for a duplicate. The code below
encounters a runtime error 2465 in not being able to find
the "field" TopicsHistory, which is not a field but is the
name of the form whose recordset is the object of the
search. Is what I've coded inappropriate for what I'm
trying to accomplish?

Me![TopicsHistory].Form.Recordset.FindFirst "Topic = """ & Me.tbTopic1 &
""""
If Me![TopicsHistory].Form.Recordset.NoMatch = False Then Me.Dup1 = "Yes"


Your code should work if TopicsHistory is a subform
(control) on form B. Also, unless you are also navigating
to the found record, you should use the RecordsetClone
property instead of Recordset.

If TopicsHistory really is a separate form, your code would
be:

With Forms!TopicsHistory.RecordsetClone
.FindFirst "Topic = """ & Me.tbTopic1 & """"
If .NoMatch Then Me.Dup1 = "Yes"
End With
 
Marsh,

TopicsHistory is in fact a separate form. So, here's the
code I used: (Works as intended)

With Forms!TopicsHistory.RecordsetClone
..FindFirst "Topic = """ & Me.tbTopic1 & """"
Me.Dup1 = Not .nomatch
End With

I also want to set the field [Dup] in TopicsHistory's recordsource,
so is:

..dup = me.dup1

the appropriate statement to immediately precede the
"End With"?

Bill

Marshall Barton said:
Bill said:
I have a form named TopicsHistory whose recordsource
is a simple query. TopicsHistory opens another form, "B",
that amongst its tasks is a search in TopicsHistory's
recordsource looking for a duplicate. The code below
encounters a runtime error 2465 in not being able to find
the "field" TopicsHistory, which is not a field but is the
name of the form whose recordset is the object of the
search. Is what I've coded inappropriate for what I'm
trying to accomplish?

Me![TopicsHistory].Form.Recordset.FindFirst "Topic = """ & Me.tbTopic1 &
""""
If Me![TopicsHistory].Form.Recordset.NoMatch = False Then Me.Dup1 = "Yes"


Your code should work if TopicsHistory is a subform
(control) on form B. Also, unless you are also navigating
to the found record, you should use the RecordsetClone
property instead of Recordset.

If TopicsHistory really is a separate form, your code would
be:

With Forms!TopicsHistory.RecordsetClone
.FindFirst "Topic = """ & Me.tbTopic1 & """"
If .NoMatch Then Me.Dup1 = "Yes"
End With
 
I've tried:
With Forms!TopicsHistory.RecordsetClone
..FindFirst "Topic = """ & Me.tbTopic1 & """"
Me.Dup1 = Not .nomatch
If Me.Dup1 then
.Edit
.Dup = Me.Dup1
End If
End With

Access doesn't complain, but the record found via
the "FindFirst" did not get its "Dup" field updated.



Marshall Barton said:
Bill said:
I have a form named TopicsHistory whose recordsource
is a simple query. TopicsHistory opens another form, "B",
that amongst its tasks is a search in TopicsHistory's
recordsource looking for a duplicate. The code below
encounters a runtime error 2465 in not being able to find
the "field" TopicsHistory, which is not a field but is the
name of the form whose recordset is the object of the
search. Is what I've coded inappropriate for what I'm
trying to accomplish?

Me![TopicsHistory].Form.Recordset.FindFirst "Topic = """ & Me.tbTopic1 &
""""
If Me![TopicsHistory].Form.Recordset.NoMatch = False Then Me.Dup1 = "Yes"


Your code should work if TopicsHistory is a subform
(control) on form B. Also, unless you are also navigating
to the found record, you should use the RecordsetClone
property instead of Recordset.

If TopicsHistory really is a separate form, your code would
be:

With Forms!TopicsHistory.RecordsetClone
.FindFirst "Topic = """ & Me.tbTopic1 & """"
If .NoMatch Then Me.Dup1 = "Yes"
End With
 
Forgot the .Update after the .Dup = Me.Dup1
All is well now.
Thanks,
Bill


Bill said:
I've tried:
With Forms!TopicsHistory.RecordsetClone
.FindFirst "Topic = """ & Me.tbTopic1 & """"
Me.Dup1 = Not .nomatch
If Me.Dup1 then
.Edit
.Dup = Me.Dup1
End If
End With

Access doesn't complain, but the record found via
the "FindFirst" did not get its "Dup" field updated.



Marshall Barton said:
Bill said:
I have a form named TopicsHistory whose recordsource
is a simple query. TopicsHistory opens another form, "B",
that amongst its tasks is a search in TopicsHistory's
recordsource looking for a duplicate. The code below
encounters a runtime error 2465 in not being able to find
the "field" TopicsHistory, which is not a field but is the
name of the form whose recordset is the object of the
search. Is what I've coded inappropriate for what I'm
trying to accomplish?

Me![TopicsHistory].Form.Recordset.FindFirst "Topic = """ & Me.tbTopic1 &
""""
If Me![TopicsHistory].Form.Recordset.NoMatch = False Then Me.Dup1 = "Yes"


Your code should work if TopicsHistory is a subform
(control) on form B. Also, unless you are also navigating
to the found record, you should use the RecordsetClone
property instead of Recordset.

If TopicsHistory really is a separate form, your code would
be:

With Forms!TopicsHistory.RecordsetClone
.FindFirst "Topic = """ & Me.tbTopic1 & """"
If .NoMatch Then Me.Dup1 = "Yes"
End With
 
Right!

Glad you were able to sort it out while I was unavailable.

Based on an old check box control bug (I think it was fixed
yeas ago), I write the If statement this way:

If Me.Dup1 = True Then
.Edit
.Dup = True
.Update
End If
--
Marsh
MVP [MS Access]

Forgot the .Update after the .Dup = Me.Dup1
All is well now.
Thanks,
Bill


Bill said:
I've tried:
With Forms!TopicsHistory.RecordsetClone
.FindFirst "Topic = """ & Me.tbTopic1 & """"
Me.Dup1 = Not .nomatch
If Me.Dup1 then
.Edit
.Dup = Me.Dup1
End If
End With

Access doesn't complain, but the record found via
the "FindFirst" did not get its "Dup" field updated.



Bill wrote:

I have a form named TopicsHistory whose recordsource
is a simple query. TopicsHistory opens another form, "B",
that amongst its tasks is a search in TopicsHistory's
recordsource looking for a duplicate. The code below
encounters a runtime error 2465 in not being able to find
the "field" TopicsHistory, which is not a field but is the
name of the form whose recordset is the object of the
search. Is what I've coded inappropriate for what I'm
trying to accomplish?

Me![TopicsHistory].Form.Recordset.FindFirst "Topic = """ & Me.tbTopic1 &
""""
If Me![TopicsHistory].Form.Recordset.NoMatch = False Then Me.Dup1 = "Yes"


Your code should work if TopicsHistory is a subform
(control) on form B. Also, unless you are also navigating
to the found record, you should use the RecordsetClone
property instead of Recordset.

If TopicsHistory really is a separate form, your code would
be:

With Forms!TopicsHistory.RecordsetClone
.FindFirst "Topic = """ & Me.tbTopic1 & """"
If .NoMatch Then Me.Dup1 = "Yes"
End With
 
The search and updates are attended to in a function, as
there are many AfterUpdate events associated with the
task. Here's the function, where you see that any possible
text box control bug should not be an issue:

Private Function MarkDuplicates(strTop As String) As Boolean
'============================================='
' "strTop" is our current choice as a new topic. So, we look in the '
' history RS to see if it's already been used. If so, we set the
'
' "duplicated" flag in the history file so the topic will show high-
'
' lighted in subsequent topic history displays.
'
'============================================='
Dim Mark As Boolean

With Forms!TopicsHistory.RecordsetClone 'Identify the history RS
..FindFirst "Topic = """ & strTop & """" 'Look for current choice
Mark = Not .nomatch 'Want "True" if found
If Mark = True Then 'Was it found?
.Edit 'Yes,
update history RS
.Dup = Ture '
.Update '
End If
End With
MarkDuplicates = Mark 'Return "find results"

End Function


Thanks for your help,
Bill








Marshall Barton said:
Right!

Glad you were able to sort it out while I was unavailable.

Based on an old check box control bug (I think it was fixed
yeas ago), I write the If statement this way:

If Me.Dup1 = True Then
.Edit
.Dup = True
.Update
End If
--
Marsh
MVP [MS Access]

Forgot the .Update after the .Dup = Me.Dup1
All is well now.
Thanks,
Bill


Bill said:
I've tried:
With Forms!TopicsHistory.RecordsetClone
.FindFirst "Topic = """ & Me.tbTopic1 & """"
Me.Dup1 = Not .nomatch
If Me.Dup1 then
.Edit
.Dup = Me.Dup1
End If
End With

Access doesn't complain, but the record found via
the "FindFirst" did not get its "Dup" field updated.



Bill wrote:

I have a form named TopicsHistory whose recordsource
is a simple query. TopicsHistory opens another form, "B",
that amongst its tasks is a search in TopicsHistory's
recordsource looking for a duplicate. The code below
encounters a runtime error 2465 in not being able to find
the "field" TopicsHistory, which is not a field but is the
name of the form whose recordset is the object of the
search. Is what I've coded inappropriate for what I'm
trying to accomplish?

Me![TopicsHistory].Form.Recordset.FindFirst "Topic = """ & Me.tbTopic1
&
""""
If Me![TopicsHistory].Form.Recordset.NoMatch = False Then Me.Dup1 =
"Yes"


Your code should work if TopicsHistory is a subform
(control) on form B. Also, unless you are also navigating
to the found record, you should use the RecordsetClone
property instead of Recordset.

If TopicsHistory really is a separate form, your code would
be:

With Forms!TopicsHistory.RecordsetClone
.FindFirst "Topic = """ & Me.tbTopic1 & """"
If .NoMatch Then Me.Dup1 = "Yes"
End With
 
It was Check Boxes, not text boxes that had a problem with
boolean fields. It's probably irrelevant now anyway, just
an old habit I have.

Your code below has a typo. If you Copied/Pasted it to
avoid posting code with extraneous errors, then I have to
assume that you have not compiled or executed the function
yet. The logic looks fine, but you should check the line:
.Dup = Ture
--
Marsh
MVP [MS Access]

The search and updates are attended to in a function, as
there are many AfterUpdate events associated with the
task. Here's the function, where you see that any possible
text box control bug should not be an issue:

Private Function MarkDuplicates(strTop As String) As Boolean
'============================================='
' "strTop" is our current choice as a new topic. So, we look in the '
' history RS to see if it's already been used. If so, we set the
'
' "duplicated" flag in the history file so the topic will show high-
'
' lighted in subsequent topic history displays.
'
'============================================='
Dim Mark As Boolean

With Forms!TopicsHistory.RecordsetClone 'Identify the history RS
.FindFirst "Topic = """ & strTop & """" 'Look for current choice
Mark = Not .nomatch 'Want "True" if found
If Mark = True Then 'Was it found?
.Edit 'Yes,
update history RS
.Dup = Ture '
.Update '
End If
End With
MarkDuplicates = Mark 'Return "find results"

End Function


Thanks for your help,
Bill








Marshall Barton said:
Right!

Glad you were able to sort it out while I was unavailable.

Based on an old check box control bug (I think it was fixed
yeas ago), I write the If statement this way:

If Me.Dup1 = True Then
.Edit
.Dup = True
.Update
End If
--
Marsh
MVP [MS Access]

Forgot the .Update after the .Dup = Me.Dup1
All is well now.
Thanks,
Bill


I've tried:
With Forms!TopicsHistory.RecordsetClone
.FindFirst "Topic = """ & Me.tbTopic1 & """"
Me.Dup1 = Not .nomatch
If Me.Dup1 then
.Edit
.Dup = Me.Dup1
End If
End With

Access doesn't complain, but the record found via
the "FindFirst" did not get its "Dup" field updated.



Bill wrote:

I have a form named TopicsHistory whose recordsource
is a simple query. TopicsHistory opens another form, "B",
that amongst its tasks is a search in TopicsHistory's
recordsource looking for a duplicate. The code below
encounters a runtime error 2465 in not being able to find
the "field" TopicsHistory, which is not a field but is the
name of the form whose recordset is the object of the
search. Is what I've coded inappropriate for what I'm
trying to accomplish?

Me![TopicsHistory].Form.Recordset.FindFirst "Topic = """ & Me.tbTopic1
&
""""
If Me![TopicsHistory].Form.Recordset.NoMatch = False Then Me.Dup1 =
"Yes"


Your code should work if TopicsHistory is a subform
(control) on form B. Also, unless you are also navigating
to the found record, you should use the RecordsetClone
property instead of Recordset.

If TopicsHistory really is a separate form, your code would
be:

With Forms!TopicsHistory.RecordsetClone
.FindFirst "Topic = """ & Me.tbTopic1 & """"
If .NoMatch Then Me.Dup1 = "Yes"
End With
 
The post was a combination of cut/paste and
manual input in trying to get the post to read
a bit easier. The typo was just that and wasn't
also made in the compiled code.

Thanks again for the help.
Bill



Marshall Barton said:
It was Check Boxes, not text boxes that had a problem with
boolean fields. It's probably irrelevant now anyway, just
an old habit I have.

Your code below has a typo. If you Copied/Pasted it to
avoid posting code with extraneous errors, then I have to
assume that you have not compiled or executed the function
yet. The logic looks fine, but you should check the line:
.Dup = Ture
--
Marsh
MVP [MS Access]

The search and updates are attended to in a function, as
there are many AfterUpdate events associated with the
task. Here's the function, where you see that any possible
text box control bug should not be an issue:

Private Function MarkDuplicates(strTop As String) As Boolean
'============================================='
' "strTop" is our current choice as a new topic. So, we look in the '
' history RS to see if it's already been used. If so, we set the
'
' "duplicated" flag in the history file so the topic will show high-
'
' lighted in subsequent topic history displays.
'
'============================================='
Dim Mark As Boolean

With Forms!TopicsHistory.RecordsetClone 'Identify the history RS
.FindFirst "Topic = """ & strTop & """" 'Look for current choice
Mark = Not .nomatch 'Want "True" if
found
If Mark = True Then 'Was it found?
.Edit 'Yes,
update history RS
.Dup = Ture '
.Update '
End If
End With
MarkDuplicates = Mark 'Return "find
results"

End Function


Thanks for your help,
Bill








Marshall Barton said:
Right!

Glad you were able to sort it out while I was unavailable.

Based on an old check box control bug (I think it was fixed
yeas ago), I write the If statement this way:

If Me.Dup1 = True Then
.Edit
.Dup = True
.Update
End If
--
Marsh
MVP [MS Access]


Bill wrote:
Forgot the .Update after the .Dup = Me.Dup1
All is well now.
Thanks,
Bill


I've tried:
With Forms!TopicsHistory.RecordsetClone
.FindFirst "Topic = """ & Me.tbTopic1 & """"
Me.Dup1 = Not .nomatch
If Me.Dup1 then
.Edit
.Dup = Me.Dup1
End If
End With

Access doesn't complain, but the record found via
the "FindFirst" did not get its "Dup" field updated.



Bill wrote:

I have a form named TopicsHistory whose recordsource
is a simple query. TopicsHistory opens another form, "B",
that amongst its tasks is a search in TopicsHistory's
recordsource looking for a duplicate. The code below
encounters a runtime error 2465 in not being able to find
the "field" TopicsHistory, which is not a field but is the
name of the form whose recordset is the object of the
search. Is what I've coded inappropriate for what I'm
trying to accomplish?

Me![TopicsHistory].Form.Recordset.FindFirst "Topic = """ &
Me.tbTopic1
&
""""
If Me![TopicsHistory].Form.Recordset.NoMatch = False Then Me.Dup1 =
"Yes"


Your code should work if TopicsHistory is a subform
(control) on form B. Also, unless you are also navigating
to the found record, you should use the RecordsetClone
property instead of Recordset.

If TopicsHistory really is a separate form, your code would
be:

With Forms!TopicsHistory.RecordsetClone
.FindFirst "Topic = """ & Me.tbTopic1 & """"
If .NoMatch Then Me.Dup1 = "Yes"
End With
 

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

Back
Top