Using labels to select records

G

Guest

I have several labels on my main page, that are used as buttons.
They all four digit names i.e "2279" corresponding to different truck numbers
When they are clicked they all open the same form.
At the top of this form is a textbox, and I would like it to display the
number of the truck selected.
The second form contains different buttons containing types of equipment on
the trucks. When I click on these buttons I would like the third form only to
display the information for the type of equipment (I have a separate table
for all the equipment) and the truck selected on the first form.

Is there anyway I can do this?
In summary, I want the second form to display the number of the truck
selected in a text box and I want the third form to display only the record
of the truck and equipment selected.

I only want to use buttons/labels as this will be used as a touch screen.

Thank you very much
 
M

Marshall Barton

ALaw said:
I have several labels on my main page, that are used as buttons.
They all four digit names i.e "2279" corresponding to different truck numbers
When they are clicked they all open the same form.
At the top of this form is a textbox, and I would like it to display the
number of the truck selected.
The second form contains different buttons containing types of equipment on
the trucks. When I click on these buttons I would like the third form only to
display the information for the type of equipment (I have a separate table
for all the equipment) and the truck selected on the first form.

Is there anyway I can do this?
In summary, I want the second form to display the number of the truck
selected in a text box and I want the third form to display only the record
of the truck and equipment selected.

I only want to use buttons/labels as this will be used as a touch screen.


You can use the OpenForm method's WhereCondition argument to
filter the form's data. For example:

DoCmd.OpenForm "trucks",
WhereCondition:= "TruckID=2279"

DoCmd.OpenForm "equipment",
WhereCondition:= "TruckID=2279 And equip=something"

Since the forms will open to a single truck, you can use a
text box bound ot the TruckID field to display it.

Note: If the TruckID field is a Text type field, use
apostrophese around the truck ID value:
DoCmd.OpenForm "trucks",
WhereCondition:= "TruckID='2279' "
Similarly for the equipment ID field.
 
G

Guest

Thanks Marshall,
I understand what you're saying, and that is exactly what I'm looking to do.
My problem now is that when I type in my arguments that way I'm getting
errors. It seems like that is not how I'm supposed to write the
"wherecondition" in Access 2007. Is there another way I can do this?
Thanks a lot
 
M

Marshall Barton

I seriously doubt that OpenForm is different in any version
of Access.

Post a Copy/Paste of your code along with the error
message(s) you are getting.

Be sure to use Debug - Compile to check for compile errors
before trying to test the code.
 
G

Guest

The OpenForm command is the same in Access 2007, and if I just use that I
have no problem opening a form on click. I cannot seem to add the Where
condition argument properly.
If I try to write
DoCmd.OpenForm "Equipment", WhereCondition:="Truck#='2315' "

There is a run-time error. It says "syntax error in date in query
expression. "
Thanks a lot for helping me out here.

Marshall Barton said:
I seriously doubt that OpenForm is different in any version
of Access.

Post a Copy/Paste of your code along with the error
message(s) you are getting.

Be sure to use Debug - Compile to check for compile errors
before trying to test the code.
--
Marsh
MVP [MS Access]

I understand what you're saying, and that is exactly what I'm looking to do.
My problem now is that when I type in my arguments that way I'm getting
errors. It seems like that is not how I'm supposed to write the
"wherecondition" in Access 2007. Is there another way I can do this?
 
M

Marshall Barton

ALaw said:
The OpenForm command is the same in Access 2007, and if I just use that I
have no problem opening a form on click. I cannot seem to add the Where
condition argument properly.
If I try to write
DoCmd.OpenForm "Equipment", WhereCondition:="Truck#='2315' "

There is a run-time error. It says "syntax error in date in query
expression. "


Ah ha! Your field name is Truck#, not TruckID.

Aby time you use a name that contains a space or any
non-alphanumeric character, you must enclose the name in [ ]

DoCmd.OpenForm "Equipment", _
WhereCondition:="[Truck#]='2315' "
 
G

Guest

Thanks a lot Marshall,
When I go from my main form to the second form it displays the numbers
exactly how I wanted it to.

I still need some help with another problem if you don't mind.
When I open the second form "Equipment" The truck number is displayed in the
text box "Truck #". This was selected with your help from a button on the
main page.

Now what I want to do is click on a type of equipment such as "Cables". When
I hit this I want it to open record in the "cables" table, but only for the
truck I selected on the main form.

How do I connect my Truck # text box from the Equipment page, to the Truck #
primary key for the Cables form?

Hope this makes sense.

Thanks a lot



Marshall Barton said:
ALaw said:
The OpenForm command is the same in Access 2007, and if I just use that I
have no problem opening a form on click. I cannot seem to add the Where
condition argument properly.
If I try to write
DoCmd.OpenForm "Equipment", WhereCondition:="Truck#='2315' "

There is a run-time error. It says "syntax error in date in query
expression. "


Ah ha! Your field name is Truck#, not TruckID.

Aby time you use a name that contains a space or any
non-alphanumeric character, you must enclose the name in [ ]

DoCmd.OpenForm "Equipment", _
WhereCondition:="[Truck#]='2315' "
 
M

Marshall Barton

Just do the same kind of thing for the cables form.

Since I don't know how your tables are designed, what the
relevant field names are nor the form's you're using, this
is a little vague and you will have to adapt it to your
specific situation:

DoCmd.OpenForm "cablesform", _
WhereCondition:="[Truck#]='" & Me.[Truck#] & "'
--
Marsh
MVP [MS Access]

When I go from my main form to the second form it displays the numbers
exactly how I wanted it to.

I still need some help with another problem if you don't mind.
When I open the second form "Equipment" The truck number is displayed in the
text box "Truck #". This was selected with your help from a button on the
main page.

Now what I want to do is click on a type of equipment such as "Cables". When
I hit this I want it to open record in the "cables" table, but only for the
truck I selected on the main form.

How do I connect my Truck # text box from the Equipment page, to the Truck #
primary key for the Cables form?


Marshall Barton said:
Ah ha! Your field name is Truck#, not TruckID.

Aby time you use a name that contains a space or any
non-alphanumeric character, you must enclose the name in [ ]

DoCmd.OpenForm "Equipment", _
WhereCondition:="[Truck#]='2315' "
 

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