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
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