Finding Text String

  • Thread starter Thread starter JamesJ
  • Start date Start date
J

JamesJ

Hi. I'm trying to find text in a certain field using the inputbox
but have not had any luck. The code below produces no errors
but does nothing.

Private Sub cmdFind_Click()

Dim Message, Title, Default, MyValue

Message = "Enter text string to find" ' Set prompt.
Title = "Find Text" ' Set title.

MyValue = InputBox(Message, Title, Default)

With Me.RecordsetClone
.FindFirst "[DvdMovieTitle]= ' " & MyValue & " ' "
End With

End Sub

Am I close??

Thanks,
James
 
James

You've described a "how". Now, what about the "what" ... what are you
trying to accomplish (forget about how you might do it)?

If you are trying to provide a way for a user to select a specific record,
based on a title (your "DVDMovieTitle"), have you considered using a combo
box which lists all the titles?

One problem I can see with the approach you are using is that it requires
the user to enter ONLY the exact, correctly-spelled title. Otherwise, it
won't be found. And since you used FindFirst, what happens if there are
three "War of the Worlds" DVDs (this happened to me at the Movie Store last
week!)?
 
For instance: if one types 'war of' in the inputbox
it finds the first instance of the text string in the DvdMovieTitle field.


Jeff Boyce said:
James

You've described a "how". Now, what about the "what" ... what are you
trying to accomplish (forget about how you might do it)?

If you are trying to provide a way for a user to select a specific record,
based on a title (your "DVDMovieTitle"), have you considered using a combo
box which lists all the titles?

One problem I can see with the approach you are using is that it requires
the user to enter ONLY the exact, correctly-spelled title. Otherwise, it
won't be found. And since you used FindFirst, what happens if there are
three "War of the Worlds" DVDs (this happened to me at the Movie Store
last
week!)?

--
Regards

Jeff Boyce
<Office/Access MVP>

JamesJ said:
Hi. I'm trying to find text in a certain field using the inputbox
but have not had any luck. The code below produces no errors
but does nothing.

Private Sub cmdFind_Click()

Dim Message, Title, Default, MyValue

Message = "Enter text string to find" ' Set prompt.
Title = "Find Text" ' Set title.

MyValue = InputBox(Message, Title, Default)

With Me.RecordsetClone
.FindFirst "[DvdMovieTitle]= ' " & MyValue & " ' "
End With

End Sub

Am I close??

Thanks,
James
 
I searched help for the bookmark property and found the code I needed:

Private Sub cmdFind_Click()

Dim rst As DAO.Recordset
Dim strCriteria As String

strCriteria = "[DvdMovieTitle] Like '*" & InputBox("Enter the " _
& "first few letters of the name to find") & "*'"

Set rst = Me.RecordsetClone
rst.FindFirst strCriteria
If rst.NoMatch Then
MsgBox "No entry found.", vbInformation
Else
Me.Bookmark = rst.Bookmark
End If

Set rst = Nothing

End Sub


JamesJ said:
For instance: if one types 'war of' in the inputbox
it finds the first instance of the text string in the DvdMovieTitle field.


Jeff Boyce said:
James

You've described a "how". Now, what about the "what" ... what are you
trying to accomplish (forget about how you might do it)?

If you are trying to provide a way for a user to select a specific
record,
based on a title (your "DVDMovieTitle"), have you considered using a
combo
box which lists all the titles?

One problem I can see with the approach you are using is that it requires
the user to enter ONLY the exact, correctly-spelled title. Otherwise, it
won't be found. And since you used FindFirst, what happens if there are
three "War of the Worlds" DVDs (this happened to me at the Movie Store
last
week!)?

--
Regards

Jeff Boyce
<Office/Access MVP>

JamesJ said:
Hi. I'm trying to find text in a certain field using the inputbox
but have not had any luck. The code below produces no errors
but does nothing.

Private Sub cmdFind_Click()

Dim Message, Title, Default, MyValue

Message = "Enter text string to find" ' Set prompt.
Title = "Find Text" ' Set title.

MyValue = InputBox(Message, Title, Default)

With Me.RecordsetClone
.FindFirst "[DvdMovieTitle]= ' " & MyValue & " ' "
End With

End Sub

Am I close??

Thanks,
James
 
James

The .FindFirst method will only find the first one. How will you
find/select the second or third?

--
Regards

Jeff Boyce
<Office/Access MVP>

JamesJ said:
I searched help for the bookmark property and found the code I needed:

Private Sub cmdFind_Click()

Dim rst As DAO.Recordset
Dim strCriteria As String

strCriteria = "[DvdMovieTitle] Like '*" & InputBox("Enter the " _
& "first few letters of the name to find") & "*'"

Set rst = Me.RecordsetClone
rst.FindFirst strCriteria
If rst.NoMatch Then
MsgBox "No entry found.", vbInformation
Else
Me.Bookmark = rst.Bookmark
End If

Set rst = Nothing

End Sub


JamesJ said:
For instance: if one types 'war of' in the inputbox
it finds the first instance of the text string in the DvdMovieTitle field.


James

You've described a "how". Now, what about the "what" ... what are you
trying to accomplish (forget about how you might do it)?

If you are trying to provide a way for a user to select a specific
record,
based on a title (your "DVDMovieTitle"), have you considered using a
combo
box which lists all the titles?

One problem I can see with the approach you are using is that it requires
the user to enter ONLY the exact, correctly-spelled title. Otherwise, it
won't be found. And since you used FindFirst, what happens if there are
three "War of the Worlds" DVDs (this happened to me at the Movie Store
last
week!)?

--
Regards

Jeff Boyce
<Office/Access MVP>

Hi. I'm trying to find text in a certain field using the inputbox
but have not had any luck. The code below produces no errors
but does nothing.

Private Sub cmdFind_Click()

Dim Message, Title, Default, MyValue

Message = "Enter text string to find" ' Set prompt.
Title = "Find Text" ' Set title.

MyValue = InputBox(Message, Title, Default)

With Me.RecordsetClone
.FindFirst "[DvdMovieTitle]= ' " & MyValue & " ' "
End With

End Sub

Am I close??

Thanks,
James
 
Back
Top