Search button that takes user entered info. and opens a new form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I have created a form that uses an unbound text box to let the user enter
a company name to search for. When the user hits enter, or clicks on the
button, I want another form to open that will display the company's record
from a table.

What code is necessary for this to happen? I want to avoid using a combo box.

Thanks!
 
DoCmd.OpenForm "formNameToOpen", WhereCondition :=
"CieName=FORMS!FormNameHere!ControlWithCompanyNameHere"


Replace formNameToOpen, CieName (the field name ), FormNameHere and
ControlWithCompanyNameHere by the appropriate names.


Hoping it may help,
Vanderghast, Access MVP
 
I almost have it working, but need a little more help.

Here is the code I wrote:

If IsNull(txtCompanyNameSearch) Then
DoCmd.OpenForm "frmCompanyInformation"
Else
strOpenArgs = txtCompanyNameSearch
DoCmd.OpenForm "frmCompanyInformation",
WhereCondition:="CompanyName=FORMS!frmCompanyInformation!txtCompanyNameSearch"
End If

Explanation: txtCompanyNameSearch is the textbox that holds the company
name the user wants to search for. frmCompanyInformation is the form that
needs to be opened to the appropriate company record.

Where you told me to replace CieName (the field name) and
ControlWithCompanyNameHere is the issue I'm having. What field name are you
referring to? The field in my table I want to search through is called
CompanyName. and I have no idea what you mean by the last part.

Thanks!
 
The form name you already have open should follow the keyword FORMS, it
seems you are using the form name you want to open.


DoCmd.OpenForm "frmCompanyInformation",
WhereCondition:="CompanyName=FORMS!frmCompanyInformation!txtCompanyNameSearch"


you see, the form name to open and the form name to read the information
from have the same name. That is probably the source of the problem.


try:


DoCmd.OpenForm "frmCompanyInformation",
WhereCondition:="CompanyName=FORMS!frmAlreadyOpen!txtCompanyNameSearch"



Vanderghast, Access MVP
 
works perfectly! thanks so much

Michel Walsh said:
The form name you already have open should follow the keyword FORMS, it
seems you are using the form name you want to open.


DoCmd.OpenForm "frmCompanyInformation",
WhereCondition:="CompanyName=FORMS!frmCompanyInformation!txtCompanyNameSearch"


you see, the form name to open and the form name to read the information
from have the same name. That is probably the source of the problem.


try:


DoCmd.OpenForm "frmCompanyInformation",
WhereCondition:="CompanyName=FORMS!frmAlreadyOpen!txtCompanyNameSearch"



Vanderghast, Access MVP
 
Back
Top