Filtered Form

  • Thread starter Thread starter JohnB762 via AccessMonster.com
  • Start date Start date
J

JohnB762 via AccessMonster.com

Hello to everybody,
I have a transparent button on an image.
With a click of mouse I would like to open a form filtered. I tryed the
following code, but doesn't work.

Private Sub Fossa6_Click()

Dim stdocname As String
Dim stLinkCriteria As String

stdocname = "tblCimitero"

stLinkCriteria = "[Tipologia]=" & Me![Fossa6]
DoCmd.OpenForm stdocname, , , stLinkCriteria

End Sub

Many thanks for your help.
Regards
John
 
How does it not "work"? Does it not open the form, or does the form open to
a blank record?
Is your form named tblCimitero? Looks more like a table to me. Is Tipologia
a numeric data type field in your table? Need more info.

Brian
 
Hi Brian,
I receive an runtime error "438".

The form where the button is placed is "pianta"
The name of the button is "Fossa6"

The form "tblCimitero" is correct as I didn't change the name when I built up
the form from the table. Nut now, I change the name to "frmCimitero"
Within this form there is a field called "Tipologia" and the content of the
field is "Fossa 6".
I would like opend the form in the spreadsheet view if possible.

Thanks for your help.
JohnB
 
Hi JohnB,

It really helps if you name your database objects so that they are
descriptive and meaningful. It is not at all clear to me whether Fossa 6, in
your WHERE clause, is the name of a control on your form (ie. Combobox,
Textbox, Listbox, etc...), or whether it is a value being displayed within
one of the aforementioned controls. I like to name my objects with a prefix
and no spaces or underscores:

frmSomething = Form
txtSomething = TextBox
cboSomething = Combobox

Also, tables have fields; queries have fields; forms have controls. So the
WHERE clause tells your frmCimitero which record from tblCimitero to load
based on the fieldname in tblCimitero and the value displayed in the control
on your Pianta form.

Anyhow, the construction of the WHERE clause is as follows:

1. [Tipologia] should be the name of a field in tblCimitero to which
frmCimitero is bound.
2. [Fossa 6] should be the name of the control on Pianta which holds the
value you wish to filter on.

if the value in Fossa 6 is a numeric data type, then the syntax would be as
follows:
"[Tipologia]=" & Me![Fossa 6]

If it is textual, then you'd use the following:
"[Tipologia]=""" & Me![Fossa 6] & """"
or
"[Tipologia]='" & Me![Fossa 6] & "'"

So assuming that [Fossa 6] is a combo (drop down box) with its bound field
being a numeric value, your code to open the Pianta form would be:

DoCmd.OpenForm "pianta" , acFormDS, , "[Tipologia]=" & Me![Fossa 6]

HTH,
Brian
 
Hi Brian,
simply thanks, and thanks to help me to understand a little bit more of
database.
The mistake I done is that [Fossa 6] is a textual value, while I used it as a
numeric.

Thanks again and regards
JohnB
 
Back
Top