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!

Need text box to function like combo box

Status
Not open for further replies.

HGoodloe

Programmer
Sep 4, 2008
53
US
Changing the variable from DBS to DAO fixed my problem and I want to thank you for that.
May I ask one last favor of you and you shouldn’t hear anymore from me for a while after this request?.

Is it possible for a text box control to function like a combo box?

In one of my projects, I’m working with a main form that includes a sub or child form. When entering the contract number in the text box on the main form I’m looking for the records associated with that number to populate or appear in the sub form.

At the moment when entering a contract number in the text box on the main form and when clicking the command button, all records do appear. The only thing, instead of those records appearing in a separate table for form, other than the sub form that is on the main form, I would like that data to populate in the sub form of the main form. Is that possible in access?

I am aware that I could easily use a combo box instead. I do have a couple of combo boxes on some of the other forms. For obvious reasons I’m wanting to use a text box that functions in the say way as a combo box if that is possible.

Thank you very much.

The following is the source code I’m currently working with:

Private Sub cmdSearch_Click()

Me.txtSearch.SetFocus
If Me.txtSearch.Text = "" Then
MsgBox "Please enter a Contract Number"
Me.txtSearch.SetFocus
Exit Sub
End If

Dim dbs As DAO.Database, rst As DAO.Recordset

Set dbs = OpenDatabase("Construction.mdb")

txtSearch.SetFocus

Set rst = dbs.OpenRecordset("Select ContractNo from tblContracts " & " Where ContractNo Like " & "'*" & _
Me.txtSearch & "*'" & ";")

If rst.RecordCount < 1 Then
MsgBox "Construction # invalid or not in database, Please try again", vbOKOnly, "Code Error"
Else

DoCmd.OpenForm "tblcontracts", acFormDS, , "ContractNo Like '*" & Forms!Construction_Records.txtSearch & "*'"

Exit Sub
End If

End Sub
 
Why using the DoCmd.OpenForm method if you don't want to open a form ?
What is the RecordSource of your subform ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The record source of my subform is tblcontracts
 
So, instead of opening a form you may apply a filter on your subform.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top