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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subform doesn't open correctly

Status
Not open for further replies.

mrbboy

Technical User
Feb 28, 2007
136
US
I am using the following code to open a form (frm_Audit) that contains a subform (frm_AuditDetails) from another form, frm_Search. This is the code in the On CLick event of a combo box in frm_Search.

Dim stDocName As String
Dim Whereclause As String

stDocName = "frm_Audit"

If Not IsNull(cbo_Status) Then
Whereclause = "Forms!frm_Audit!frm_AuditDetails.Form![Status] = '" & cbo_Status & "'"
End If

This only opens a blank form. If I substitute the frm_AuditDetails for stDocName and "[Status] = '" etc in the whereclause, the code works. Cam someone tell me what I am doing wrong?
Can someone tell me why this doesn't work?
 
I forgot to include this code at the end.

DoCmd.OpenForm stDocName, , , Whereclause
 
I changed the code to because the name of the control is actually [Status]. I was using the subform name instead of the control name.

If Not IsNull(cbo_Status) Then
Whereclause = "Forms![frm_Audit]![Status].Form![Status] = '" & cbo_Status & "'"
End If

When I run this code, I message box appears prompting me to enter a value (text). When I enter a status, i.e. In Progress, into the field, the form opens with the correct records. Why does the message box appear? When I placed a break point on the Whereclause statement and ran the code, the whereclause has this value:

Whereclause = "Forms![frm_Audit]![Status].Form![Status] = 'In Progress'

Any ideas where I can be doing this wrong?
 
How are ya mrbboy . . .

It appears you have a form referencing problem.

Have a look here: Refer to Form and Subform properties and controls

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
I am so confused. When I use

Whereclause = "Forms!frm_Audit!frm_AuditDetails.Form![Status] = '" & cbo_Status & "'"

where frm_AuditDetails is the name of the subform. I get a blank form. WHen I use

Whereclause = "Forms![frm_Audit]![Status].Form![Status] = '" & cbo_Status & "'"

a message box appears prompting me to enter the status again. I already chose the status using cbo_Status from another form, frm_View.
 
You can not do this. What actually are you trying to do?

You are asking to open form Audit, where the value on form Audits subform equals some value.

You need to open form Audit and tell it what field value of form Audit to go to. If [status] is a field on the form audit then it makes sense to say something like

open form audit where the value of form audit's status field equals some value.

but it does not make any sense to say

open form audit where the value of form audit's subform which may have a status field equals some value.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top