Me!

  • Thread starter Thread starter rob c
  • Start date Start date
R

rob c

I am working on a subform and have two columns, "columnone" and "columntwo".

I have entered info into "columnone" and want that choice to control the
choices available in "columntwo".

Should putting "Me!columnone" as the paramater in my Row Source statement
accomplish this? I keep getting the popup box that asks for a paramater.

I am attempting to learn how to use "Me!" so please either answer this
specific question and don't tell me about cascading or send me off to look at
something else.

Thank you.
 
Rob,

The rowsource of your second combo box has to be set to a string value. It
sounds like you are trying something like this.

Me!cboCombo2.Rowsource = "SELECT * FROM Table2 WHERE
Field1=Me!cboCombo1"

The correct syntax is:

Me!cboCombo2.Rowsource = "SELECT * FROM Table2 WHERE Field1=" &
Me!cboCombo1

This passes as string statement with the value of your combo box, not the
reference to the combo box itself. One note - if your data is text, you'll
need to embed single quotes in your code:

Me!cboCombo2.Rowsource = "SELECT * FROM Table2 WHERE Field1='" &
Me!cboCombo1 & "'"


Hope this helps
 
Sean,
Thanks for the information, it was exactly what I needed.
I know understand how to do what I was initially trying to accomplish and
why what I was trying wasn't working.
Regards,
Rob

Beetle said:
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;
 
Back
Top