Invalid use of Me keyword ??? (1 Viewer)

IanWright

Registered User.
Local time
Today, 02:17
Joined
Jul 13, 2005
Messages
23
I've got the following code:

Option Compare Database
Public Function getColour() As String
getColour = Me!frmRooms.Form!subfrmChairs.Controls("ColourTypes").Value
End Function
Public Function getType() As String
getType = Me!frmRooms.Form!subfrmChairs.Controls("ChairStyle").Value
End Function
Public Function getCondition() As String
getCondition = Me!frmRooms.Form!subfrmChairs.Controls("Condition").Value
End Function
Public Function getArms() As Boolean
getArms = Me!frmRooms.Form!subfrmChairs.Controls("Arms").Value
End Function

then the following query:

SELECT Items.ItemID, Items.ItemType, Items.ColourTypes, Items.Condition, Items.Arms
FROM Items
WHERE (((Items.ItemType)=getType()) AND ((Items.ColourTypes)=getColour()) AND ((Items.Condition)=getCondition()) AND ((Items.Arms)=getArms()));

I open my form, move to a record who's subform has some chairs in, run the query and get an "Invalid use of Me keyword" error. Can anyone tell me why and how to get round this?

Thanks
 

IanWright

Registered User.
Local time
Today, 02:17
Joined
Jul 13, 2005
Messages
23
I used that the first time round..

noticed a couple of problems, so tried this instead:

getArms = Me!subfrmChairs.Form!StyleID.Value

still doesn't work though :S Could you give me an example of one that would work, as I'm not sure whats wrong with that..
 

RuralGuy

AWF VIP
Local time
Today, 03:17
Joined
Jul 2, 2005
Messages
13,826
Are your Functions is a Form Module or a Standard Module?
 

IanWright

Registered User.
Local time
Today, 02:17
Joined
Jul 13, 2005
Messages
23
They were in a seperate standard module, think i've tried on a form too, I think I'd prefer the code on the form itself really
 
Last edited:

RuralGuy

AWF VIP
Local time
Today, 03:17
Joined
Jul 2, 2005
Messages
13,826
In a Standard module you will need to use the Forms collection:

Forms!frmRooms.subfrmChairs.Form.Condition

...should do it. "subfrmChairs" needs to be the name of the SubFormControl on the form "frmRooms" and not necessarily the SubFormName. They are usually named the same but they do not have to be.

New Info: Putting functions in a query will slow it down dramatically. Why not just refer to the control directly in the query?
 
Last edited:

IanWright

Registered User.
Local time
Today, 02:17
Joined
Jul 13, 2005
Messages
23
Ok, I think I've got it, doing it from an external module similar to what you've said there..

Public Function getType() As String
getType = Forms!frmRooms.subfrmChairs!Controls.ChairStyle.Value
End Function

however I get an "Application-defined or object-defined error" Run-time 2465 now :S
 

IanWright

Registered User.
Local time
Today, 02:17
Joined
Jul 13, 2005
Messages
23
Oh and in reply, mainly because I'm not sure how. I thought I read a couple of posts on here saying it wasn't possible to refer to a control from a query...
 

RuralGuy

AWF VIP
Local time
Today, 03:17
Joined
Jul 2, 2005
Messages
13,826
Try what I supplied and tell me what happens.
 

IanWright

Registered User.
Local time
Today, 02:17
Joined
Jul 13, 2005
Messages
23
getType = Forms!frmRooms.subfrmChairs.Form.Controls.ChairStyle.Value
getType = Forms!frmRooms.subfrmChairs.Form.ChairStyle.Value

Tried both them, also with ! between Form and the Controls/Chairstyle bits, getting the same error message as I got with the code I posted before each time.
 

RuralGuy

AWF VIP
Local time
Today, 03:17
Joined
Jul 2, 2005
Messages
13,826
Leave off the .value!

Addl Info: This will only work when frmRooms is open!
 
Last edited:

IanWright

Registered User.
Local time
Today, 02:17
Joined
Jul 13, 2005
Messages
23
Still get error msgs :S

Yeah I know, I've always got the form open, if I attached the database would that help?#

I've added the file if you want to look at it at all. Opening the form and selecting the Chairs tab, and B007 in the combo box is what I've been using, then running the query. I'm just wondering if the fact I'm using tabs might cause a problem or not..
 

Attachments

  • Audit.zip
    104.5 KB · Views: 199
Last edited:

RuralGuy

AWF VIP
Local time
Today, 03:17
Joined
Jul 2, 2005
Messages
13,826
I'll look at it and be right with you. The Tab object does not change the reference at all.
 

RuralGuy

AWF VIP
Local time
Today, 03:17
Joined
Jul 2, 2005
Messages
13,826
You can just call me RG for short. ;)

Your biggest issue is your SubFormControl is named [Chairs Subform], not subfrmChairs. "subfrmChairs" is the name of the SubForm not the SubFormControl. By the way, using spaces in *any* names will cause you unexpected grief some day. Better to use CamelFontNames or Under_Score_Names.

Once you get your code working you should probably describe what you are trying to accomplish. Your SubForm is a Continuous Form so the query will only pick up the current record data.
 

IanWright

Registered User.
Local time
Today, 02:17
Joined
Jul 13, 2005
Messages
23
Oh, where abouts are the names then? I must have renamed it sometime or something..

I want it to only pick up the last record, this query is for data entry, to grab the ItemID#, then I can write that into a table, and refresh the form. So what the user will actually be doing is typing data into some unbound boxes, and upon the refresh an extra row will appear with their new data in, and some more unbound boxes below..
 

IanWright

Registered User.
Local time
Today, 02:17
Joined
Jul 13, 2005
Messages
23
Ahh, found that subform control thing, renamed it and it works :D

Now I've just gotta figure out why my query result is empty :| Woo, sorted. Thanks very much for the help RG :)
 
Last edited:

Users who are viewing this thread

Top Bottom