Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Search Control 1

Status
Not open for further replies.

CharlieT302

Instructor
Mar 17, 2005
406
US
Hi,

I have a main form with two subforms. Both subforms have a common field and value (Tracker field). On the second form, I want to be able to quickly locate a record whose <Tracker> field matches that displayed on the first subform.

Here is my current code (attached to a button on the 2nd subform):
************************************************************
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[Tracker Number] = " & Parent!Frm_Tracker_Sub.Form![Tracker Number]
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

GoTo exit_sub
************************************************************

When ran, the code does locate the value from the first subform. However, rather than using it as a search value on the 2nd subform, I get an error message saying that the value is not recognized as a valid field name or expression.



 
Is tracker number text or numeric?
I always recommend using something like:
Me.Parent!...

If that doesn't work, I would place a text box on the main form "txtTrackerNumber" and use code in the On Current of the first subform to set the value. Then you code can reference txtTrackerNumber or possibly using it as Link Master/Child for the second subform.

Duane
Hook'D on Access
MS Access MVP
 
How are ya CharlieT302 . . .

Perhaps this:
Code:
[blue]   Dim rs As DAO.Recordset, Cri As String
   
   Set rs = Me.Recordset.Clone
   Cri = "[Tracker Number] = " & Me.Parent!Frm_Tracker_Sub.Form![Tracker Number]
   rs.FindFirst Cri
   
   If Not rs.NoMatch Then
      Me.Bookmark = rs.Bookmark
   Else
      MsgBox "Record Not Found!"
   End If
   
   Set rst = Nothing[/blue]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Dhookum

The field is actually text field. I tried the Me.Parent!... option without success. I would rather not mess with the main form if I do not have to.

There must be a simply syntax error in my code. The error message I receive actually shows the current value, so it is obviously "seeing" the value.

 
Hey AceMan,

I plugged in your code, but received the exact same error message.

The error: 3070 Access database engine does not recognize 'smith10' as a valid field name or expression.

Where 'smith10' is the value from the first subform; so it "is" seeing the value, just not applying it to a search value on the 2nd subform.
 
As a side note, I was looking up the error code on the Microsoft's web site. They mentioned this happening with crosstab queries using parameters. I have neither, but the control source for both subforms is a SQL statement. I converted the statement into a query and used that as the data source for the form. However, it made no difference.

Could there be another structural component to the data source of form that is preventing a search?
 
If your field is text, you have to treat it like text not a number....
Code:
rs.FindFirst "[Tracker Number] = """ & Parent!Frm_Tracker_Sub.Form![Tracker Number] & """"


Duane
Hook'D on Access
MS Access MVP
 
CharlieT302 . . .

... and this:
Code:
[blue]   Dim Dat As Long, rs As DAO.Recordset, Cri As String
   
   Set rs = Me.Recordset.Clone
   Cri = "[Tracker Number] = " & Forms![purple][b]MainformName[/b][/purple]!Frm_Tracker_Sub.Form![Tracker Number]
   rs.FindFirst Cri
   
   If Not rs.NoMatch Then
      Me.Bookmark = rs.Bookmark
   Else
      MsgBox "Record Not Found!"
   End If
   
   Set rst = Nothing[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top