Results 1 to 2 of 2
Thread: VB Reference to Query (2000)
2002-11-14, 15:29 #1
- Join Date
- Nov 2001
- Thanked 0 Times in 0 Posts
VB Reference to Query (2000)
I have a qry (qrySecurity) which has true/false values for system options (Module_Menu_Athlete). I want to be able to reference the field in the query. I know when the field resides or is attached to the form it would be Me.Module_Menu_Athlete, but I tried qrySecurity.Module_Menu_Athlete and it does not work. Any advise???
Private Sub Form_Open(Cancel As Integer)
Me!MainMenuButtonAthetes.Enabled = Me.Module_Menu_Athlete
2002-11-14, 15:48 #2
- Join Date
- Mar 2002
- Thanked 30 Times in 30 Posts
Re: VB Reference to Query (2000)
You can't refer to (the value of) a field in a query as queryname.fieldname; this syntax just isn't supported. Besides, a query can return many records, so what would "the" value of a field be? (In a form, you can do that, because a form has a current record. "The" value of a control or field on a form is the value in the current record.)
One way to retrieve a value from a table or query is DLookup:
DLookup("Module_Menu_Athlete", "qrySecurity") will return the value of Module_Menu_Athlete for the first record that is returned by the query. You can also specify a where-condition: DLookup("Module_Menu_Athlete", "qrySecurity", "ID=" & Me!ID) will return the value of Module_Menu_Athlete for the record with ID equal to the current value of ID in the form.
Another way would be to open the query as a recordset.