Help Criteria in Query

  • Thread starter mattc66 via AccessMonster.com
  • Start date
M

mattc66 via AccessMonster.com

I want to double Click on a field in my form and open a query and the where
clause filters the data and only shows me the records that match. I added the
below WHERE clause, but it doesn't seem to work. Can anyone help with the
correct syntax?

Private Sub Name_DblClick(Cancel As Integer)

Dim StDocName As String

stDocName = "QueryName"
DoCmd.OpenQuery stDocName, acNormal, acEdit

End Sub

SELECT TableName.*
FROM TableName
WHERE (((TableName.FieldName)=[forms]![frmMainName]![form]![sfrmSubFormName]!
[FieldName]));
 
M

MGFoster

mattc66 said:
I want to double Click on a field in my form and open a query and the where
clause filters the data and only shows me the records that match. I added the
below WHERE clause, but it doesn't seem to work. Can anyone help with the
correct syntax?

Private Sub Name_DblClick(Cancel As Integer)

Dim StDocName As String

stDocName = "QueryName"
DoCmd.OpenQuery stDocName, acNormal, acEdit

End Sub

SELECT TableName.*
FROM TableName
WHERE (((TableName.FieldName)=[forms]![frmMainName]![form]![sfrmSubFormName]!
[FieldName]));

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Correct syntax for referencing a sub-form:

Forms!FormName.Form!SubFormName!ControlName

A "dot" goes between the FormName and the word "Form."

Sometimes a query will work better when you define the parameter, like
this:

PARAMETERS Forms!FormName.Form!SubFormName!ControlName Integer;
SELECT ...
FROM ...
WHERE ColumnName = Forms!FormName.Form!SubFormName!ControlName

Change the data type (Integer) in the PARAMETERS clause to match the
data type in the form's control.

HTH,
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBSeO004echKqOuFEgEQIrKACgrhvy30h5a+szSpCIA2whzBeLl2UAoI7P
ybxGUFkt9mMprOnnRk8ExFGb
=+LFV
-----END PGP SIGNATURE-----
 

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