Open form using vba

G

Guest

I have a table full of names and address. I have a search form with a text
box for data I enter and a combo box that lists the fields of the table. I
want to search the selected field of the combo box for the data I enter in
the text box. For example I type a last name and then select last name in
the combo box. I want the on click event to open up a form "search results"
showing the record that matches the last name or whatever data I type and
select. Any help???
 
D

Douglas J. Steele

Try something like:

DoCmd.OpenForm "MyForm", _
WhereCondition:="[MyField] = " & Chr$(34) & _
Me.MyCombobox & Chr$(34)

Replace MyForm, MyField, MyCombobox with the actual names.

If you wanted to have a text box that you could type part of the name in,
you could use something like:

DoCmd.OpenForm "MyForm", _
WhereCondition:="[MyField] Like " & Chr$(34) & _
Me.MyTextbox & "*" & Chr$(34)
 
G

Guest

I appreciate the quick response but it still gives me a blank result. No
error either.

Douglas J. Steele said:
Try something like:

DoCmd.OpenForm "MyForm", _
WhereCondition:="[MyField] = " & Chr$(34) & _
Me.MyCombobox & Chr$(34)

Replace MyForm, MyField, MyCombobox with the actual names.

If you wanted to have a text box that you could type part of the name in,
you could use something like:

DoCmd.OpenForm "MyForm", _
WhereCondition:="[MyField] Like " & Chr$(34) & _
Me.MyTextbox & "*" & Chr$(34)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Joe said:
I have a table full of names and address. I have a search form with a text
box for data I enter and a combo box that lists the fields of the table.
I
want to search the selected field of the combo box for the data I enter in
the text box. For example I type a last name and then select last name in
the combo box. I want the on click event to open up a form "search
results"
showing the record that matches the last name or whatever data I type and
select. Any help???
 
G

Guest

I have also tried this but it does not work either. But I do know that the
strings are working properly. I used msgbox to display their values.

Dim field As String
Dim search As String

field = [Combo6]
search = [namebox]

DoCmd.OpenForm "testdata1", _
WhereCondition:="testdata!field" = "search"
 
D

Douglas J. Steele

What exactly did you use? The code you posted elsewhere in this thread
(WhereCondition:="testdata!field" = "search") is definitely incorrect.


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Joe said:
I appreciate the quick response but it still gives me a blank result. No
error either.

Douglas J. Steele said:
Try something like:

DoCmd.OpenForm "MyForm", _
WhereCondition:="[MyField] = " & Chr$(34) & _
Me.MyCombobox & Chr$(34)

Replace MyForm, MyField, MyCombobox with the actual names.

If you wanted to have a text box that you could type part of the name in,
you could use something like:

DoCmd.OpenForm "MyForm", _
WhereCondition:="[MyField] Like " & Chr$(34) & _
Me.MyTextbox & "*" & Chr$(34)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Joe said:
I have a table full of names and address. I have a search form with a
text
box for data I enter and a combo box that lists the fields of the
table.
I
want to search the selected field of the combo box for the data I enter
in
the text box. For example I type a last name and then select last name
in
the combo box. I want the on click event to open up a form "search
results"
showing the record that matches the last name or whatever data I type
and
select. Any help???
 
G

Guest

I used the code you suggested, both ways and it did not work. So then I
tried the other that I pasted in below. Testdata is the table.

Douglas J. Steele said:
What exactly did you use? The code you posted elsewhere in this thread
(WhereCondition:="testdata!field" = "search") is definitely incorrect.


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Joe said:
I appreciate the quick response but it still gives me a blank result. No
error either.

Douglas J. Steele said:
Try something like:

DoCmd.OpenForm "MyForm", _
WhereCondition:="[MyField] = " & Chr$(34) & _
Me.MyCombobox & Chr$(34)

Replace MyForm, MyField, MyCombobox with the actual names.

If you wanted to have a text box that you could type part of the name in,
you could use something like:

DoCmd.OpenForm "MyForm", _
WhereCondition:="[MyField] Like " & Chr$(34) & _
Me.MyTextbox & "*" & Chr$(34)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I have a table full of names and address. I have a search form with a
text
box for data I enter and a combo box that lists the fields of the
table.
I
want to search the selected field of the combo box for the data I enter
in
the text box. For example I type a last name and then select last name
in
the combo box. I want the on click event to open up a form "search
results"
showing the record that matches the last name or whatever data I type
and
select. Any help???
 
D

Douglas J. Steele

Copy and paste the code you're trying to use. That's the only way we'll be
able to spot if you made typos in it.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Joe said:
I used the code you suggested, both ways and it did not work. So then I
tried the other that I pasted in below. Testdata is the table.

Douglas J. Steele said:
What exactly did you use? The code you posted elsewhere in this thread
(WhereCondition:="testdata!field" = "search") is definitely incorrect.


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Joe said:
I appreciate the quick response but it still gives me a blank result.
No
error either.

:

Try something like:

DoCmd.OpenForm "MyForm", _
WhereCondition:="[MyField] = " & Chr$(34) & _
Me.MyCombobox & Chr$(34)

Replace MyForm, MyField, MyCombobox with the actual names.

If you wanted to have a text box that you could type part of the name
in,
you could use something like:

DoCmd.OpenForm "MyForm", _
WhereCondition:="[MyField] Like " & Chr$(34) & _
Me.MyTextbox & "*" & Chr$(34)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I have a table full of names and address. I have a search form with
a
text
box for data I enter and a combo box that lists the fields of the
table.
I
want to search the selected field of the combo box for the data I
enter
in
the text box. For example I type a last name and then select last
name
in
the combo box. I want the on click event to open up a form "search
results"
showing the record that matches the last name or whatever data I
type
and
select. Any help???
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top