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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Look up

Status
Not open for further replies.

at51178

Technical User
Mar 25, 2002
587
US
Hey guys I would like to create a form where
I type in a name in an unbound text box and when I click on the command button it searches another text box on the form that is linked to a table that will display the record that I typed in the unbound text basically I am looking for a way to search my database by typing info in an unbound box and using code to filter for the bound text box let me know if this can be done thanks.

 
ok.
You want to search the underlying records for a given criteria that you specify.
Ok, here is a way using code. It is kind of general because I don't really know what your database is supposed to do

Private Sub Command6_Click()
On Error GoTo Command_Click_Err

Dim CurConn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim CurDB As Database

Set CurDB = CurrentDb
Set CurConn = New ADODB.Connection

With CurConn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "data source= " & CurDB.Name
.Open
End With

Set rst = New ADODB.Recordset
rst.CursorType = adOpenDynamic
rst.LockType = adLockOptimistic

rst.Open "SELECT * FROM name_of_your_table_here WHERE field_in_table_to_search = ME![name_of_unbound_textbox]", CurConn, , , adCmdText

'displays the information pertaining to the record on form
Me![Text0] = rst![field0]
Me![Text2] = rst![field1]
Me![Text4] = rst![field2]
etc...
rst.Update
rst.Close

Command_Click_Exit:
Exit Sub

Command_Click_Err:
MsgBox Err.Description
Resume Command_Click_Exit

End Sub

Hope this helps!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top