Query related to different buttons (1 Viewer)

carlosdpr

Registered User.
Local time
Today, 10:10
Joined
May 2, 2016
Messages
16
I have a form that has like 20 buttons (each button is related to a bed), like a scheme of where are the beds in a inn.
I want to know if it is possible when I click in button 1 to show me the results of the query. The query would be to show the time that the bed is occupied (so it will have like some enter dates and the end dates). The problem is not how to do the query.

The question is if I have to do 20 querys (1 for each bed) or can the query be related to all the buttons someway. If I open this form and click in button 2 (bed 2) it will show me the results for bed 2, and then if I go back and click in button 3 (bed 3) it will show me the results for bed 3.

Is this possible? Thanks in advance!
 

moke123

AWF VIP
Local time
Today, 05:10
Joined
Jan 11, 2013
Messages
3,921
yes it is possible and many ways to do it but a lot depends on what you're doing with it. Do you want to just filter a subform or open a new form with the results?
 

carlosdpr

Registered User.
Local time
Today, 10:10
Joined
May 2, 2016
Messages
16
yes it is possible and many ways to do it but a lot depends on what you're doing with it. Do you want to just filter a subform or open a new form with the results?

I want to open a table, like the table that open when you run a query. Or it can open a report associated to that query result...

The problem is the query to be related to "all the buttons" and to show different things when I click a different button.
 

moke123

AWF VIP
Local time
Today, 05:10
Joined
Jan 11, 2013
Messages
3,921
you shouldnt really expose table data, you should use forms or reports to display it. I dont think you need to pass the data to a query but rather pass a where clause to a form or report.
the docmd.openform method has these arguements -
docmd.OpenForm(FormName, View, FilterName, WhereCondition, DataMode, WindowMode, OpenArgs)

so to open a form, lets call it "frmUsedBeds" and suppose BedID is a field in the form, and you wanted it to show all records for Bed2, under button 2 click event you would have -
docmd.openform "frmUsedBeds",,,"BedID = 2"
the 4th arguement is the where condition and would open the form to show the records for bed2.

each buttons click event would have the same code but substitute the 2 for the corresponding BedID.
 

carlosdpr

Registered User.
Local time
Today, 10:10
Joined
May 2, 2016
Messages
16
Thanks! I understand what you are saying and it has more logic. I will try this, and if I encounter some problem I will post it.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 02:10
Joined
Aug 30, 2003
Messages
36,126
What do you mean to hard code the value for each button? How can I do this?
I don't know what the tag property is...I will search about that.

Simplest is hard coding the value:

DoCmd.OpenForm "SecondFormName", , , "FieldName = 123"
 

Users who are viewing this thread

Top Bottom