The Me keyword is a Visual Basic reference. It refers to the module in which
the code is currently executing. So, suppose I have a form named
frmMyForm. If I have any code behind this form it will be in a module
named frmMyForm. If, within the code, I want to refer to a property or
an object of this form I can do it in two ways. Either;
Forms!frmMyForm!cboMyComboBox
Or I can use the much simpler reference of;
Me!cboMyComboBox
However, if you are working directly (not through VBA) in the property
of a control (like the Row Source of a combo box), you cannot use
the Me keyword.
Now let's suppose I have two tables - one for Product Types and one
for Products - and I have a form with two combo boxes. In the first
combo box (cboTypes) I want to show Product Types so I give it
a Row Source of;
SELECT TypeID, TypeName FROM tblProductTypes ORDER BY TypeName
Then in the second combo box (cboProducts) I want to show only the
Products that are related to the Product Type I selected in the cboTypes.
I would give it a Row Source of;
SELECT ProductID, TypeID, ProductName FROM tblProducts
WHERE TypeID = [cboTypes] ORDER BY ProductName
Since I am entering this directly in the Row Source property of
cboProducts I don't use the Me keyword, as Access would have
no idea what Me refers to (since it is a VBA reference and not an
Access reference).
But I do need to requery cboProducts any time I select a new value
in cboTypes, so in the After Update event of cboTypes I enter
the following code;
Private Sub cboTypes_AfterUpdate()
Me!cboProducts.Requery
End Sub
Since I am doing the above in VBA code, I use the Me keyword.
Now, if you were using VBA to manipulate the Row Source of a
control on your form, then you could do;
Me!cboMyCombo.RowSource = "SELECT ThisField FROM ThatTable
WHERE SomeField = " &
Me!SomeControl
In the above, VBA would retrieve the value of Me!SomeControl, insert
that value as criteria for the SQL statement an then apply the resulting
SQL as the Row Source of Me!MyCombo
Sorry if this is oversimplifying it a bit, but you asked so. . .
--
_________
Sean Bailey
rob c said:
Thanks Scott,
My Table2 is called "yesorno"
Field1 is called "prodtype"
Combo1 is called "newtype"
Is the following statement the way it should be set up? Including quatation
marks?
"SELECT * FROM yesorno WHERE
prodtype=" & Me!newtype;