Bais button query

G

Guest

Dear all

I only know the basics of access and have thus a simple question.
I need to make a query in a form.
Somthing like
Select Paramter1, Parameter2 from Table1
Where Parameter1= "x"
and parameter2 = 10
and paramter3 = 4

x should be a value that I can choose from in a combobox in the form.

questions:
1) How can I make a query with the variable "x" that gets it's value from a
combobox
2) How can I make the button perfom that query
 
S

Stefan Hoffmann

hi Torch,
Select Paramter1, Parameter2 from Table1
Where Parameter1= "x"
and parameter2 = 10
and paramter3 = 4

x should be a value that I can choose from in a combobox in the form.

questions:
1) How can I make a query with the variable "x" that gets it's value from a
combobox
Enter as criteria in the query designer instead of "x"

Forms![yourFormname]![yourComboboxname].Value
2) How can I make the button perfom that query
You can't perform a select query. If this query is the record source of
a form:

Forms![yourFormname].Form.Requery

Otherwise, if you like to show the result:

DoCmd.OpenQuery "yourQueryname"



mfG
--> stefan <--
 
G

Graham R Seach

Let's assume you want to display the results of this query in a listbox on
the same form, and let's call this listbox "lstMyListbox".Let's also assume
that the combo from which you select Parameter1 is called "cboMyCombo".

Set lstMyListbox's properties as follows:
ColumnCount: 2
ColumnWidths: 3cm;3cm (or whatever measurement system you use)
Width: 3cm
RowSource: SELECT Parameter1, Parameter2
FROM Table1
WHERE Parameter1 = '" & me!cboMyCombo & "'
AND Parameter2 = 10 AND Parameter3 = 4"

Of course, the entire text of the RowSource should be entered on one
contiguous line. The RowSource assumes that Parameter1 is text. If it's a
number, use the following instead:
RowSource: SELECT Parameter1, Parameter2
FROM Table1
WHERE Parameter1 = " & me!cboMyCombo & "
AND Parameter2 = 10 AND Parameter3 = 4"

Add the following code to TWO places; the form's Current event AND
cboMyCombo's AfterUpdate event:
Me!lstMyListbox.Requery

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
G

Graham R Seach

Bugger! I wasn't thinking straight! Stefan is right; the reference to the
combo should be Forms!myFormname!cboMyCombo. Therefore, the code should be:

RowSource: SELECT Parameter1, Parameter2
FROM Table1
WHERE Parameter1 = '" & Forms!myForm!cboMyCombo & "'
AND Parameter2 = 10 AND Parameter3 = 4"

....or where Parameter1 is numeric...

RowSource: SELECT Parameter1, Parameter2
FROM Table1
WHERE Parameter1 = " & Forms!myForm!cboMyCombo
AND Parameter2 = 10 AND Parameter3 = 4"

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
G

Guest

Dear Stefan.

I understand the principle, but I think I have made a syntax error in my
WHERE statement.
My action does not return any results, whereas when I type in the WHERE
statement manually it does give me back the wanted result

Can you help me with my syntax?WHERE ((([HORA1 rauwe data].Para)="°C M3rild") AND (([HORA1 rauwe
data].Machine)="Forms![Form1]![Combo3].Value"));


Stefan Hoffmann said:
hi Torch,
Select Paramter1, Parameter2 from Table1
Where Parameter1= "x"
and parameter2 = 10
and paramter3 = 4

x should be a value that I can choose from in a combobox in the form.

questions:
1) How can I make a query with the variable "x" that gets it's value from a
combobox
Enter as criteria in the query designer instead of "x"

Forms![yourFormname]![yourComboboxname].Value
2) How can I make the button perfom that query
You can't perform a select query. If this query is the record source of
a form:

Forms![yourFormname].Form.Requery

Otherwise, if you like to show the result:

DoCmd.OpenQuery "yourQueryname"



mfG
--> stefan <--
 
S

Stefan Hoffmann

hi Torch,
Can you help me with my syntax?
WHERE ((([HORA1 rauwe data].Para)="°C M3rild") AND (([HORA1 rauwe
data].Machine)="Forms![Form1]![Combo3].Value"));
You have to omit the quotes:

([HORA1 rauwe data].Machine=Forms![Form1]![Combo3].Value);



mfG
--> stefan <--
 

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