Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reference a field in a subform

Status
Not open for further replies.

allenEd

Technical User
Nov 14, 2002
129
GB
Hi,

I am trying to reference a field in a subform to see if it's "wires only".

My code is like

If Me!qryInstallsubform.installName = "wires only" Then....

Where qryInstallsubform is the subform and the field in the sub form Im querying is called "installName" which in this case is "wires 0nly.

Can any one help?

 
Hiya,

Try this...

FORMS!mainform!qryInstallsubform.FORM.installname

or:

me!qryInstallsubform.FORM.installname

It's not very intuitive when referring to subform controls.

Regards,

Darrylle


"Never argue with an idiot, he'll bring you down to his level - then beat you with experience."
 
Can you explain more about what you're trying to do?

If I understand you correctly you want to know if information in a subform named "qryInstallsubform" has a field named "installName" and if it == "wires 0nly" you want some code to be executed?

If I'm understanding you correctly I would do the following:

write code to create a temporary query that containts that record's subform information. then, do the following

Code:
Dim db As Database
Dim myRecordSet As Recordset
Dim varselect As String

Set db = CurrentDb()
Set myRecordSet = db.OpenRecordset("name of query that has the information of the subform for whatever selected record")

If myRecordSet.BOF = True Then Exit Sub
With myRecordSet
    If .RecordCount Then
        .MoveFirst
        Do Until myRecordSet.EOF
         varselect = ![installName]
        if varselect = "wires only" then
        'blah blah
        'words words words..
        end if
    End if
End With

an example of making a tempory query and deleting it can be found under: CreateQueryDef Method Example (Microsoft Access).

If this doesn't help sorry :) but hope it does!







Cruz'n and Booz'n always.
This post shows what little I do at work.
 
Thanks you guys,

Sorted.

If Me.qryInstall_subform.Form.installname = "Wires Only" Then... worked (note no ! after me)

Much Appricated,
Allen
 
Hiya Allen,

Yep - you don't need bangs (!), (.) will do, you do need the 'FORM' part however.

Hwk - I was also confused by Allen using the qry prefix for a form - absolutely a no-no. But after an hour of reading his question, I managed to guess that qryInstallSubForm was in fact a form (and not a query as it should be with that name).

Hopefully Allen will read this.

Regards,

D



"Never argue with an idiot, he'll bring you down to his level - then beat you with experience."
 
Thanks for your help, I take your point about correct notation.


Allen
:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top