features not working on form when added as subform

SoxPats83

Registered User.
Local time
Today, 17:44
Joined
May 7, 2010
Messages
196
i have a form with a subform in it. as itself this form features a functioning search function. when i take this form and add it into another form as a subform the search function stops working. any help on this would be appreciated as i have made no changes to it, just simply dragged and dropped the form into this new form.

thanks!
 
Yep, and it is likely that the form references you used are no longer valid because subforms have a different way of being referenced. So, let's dig in. What code do you have right now, if any to do the search? Are you using a query with a reference to the form?
 
Does your search function work by returning values from a query where the criteria line refers to something like [Forms]![YourForm]![YourSearchField] ? If so, now that the form is on another form I *think* you need to specify [Forms]![YourParentForm]![YourSubForm]![YourSearchField]

Basically the location of your search field has changed so you need to give the query its new "address"
 
Yep, and it is likely that the form references you used are no longer valid because subforms have a different way of being referenced. So, let's dig in. What code do you have right now, if any to do the search? Are you using a query with a reference to the form?
thanks for the prompt reply.

below is the code i have been using on the form when it is by itself before i drag it into the other form:

Private Sub cmdSearch_Click()
Dim strRef As String
Dim strSearch As String

'Check txtSearch for Null value or Nill Entry first.
If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
Exit Sub
End If
'---------------------------------------------------------------

'Performs the search using value entered into txtSearch
'and evaluates this against values in ID

DoCmd.ShowAllRecords
DoCmd.GoToControl ("strID")
DoCmd.FindRecord Me!txtSearch

strID.SetFocus
strRef = strID.Text
txtSearch.SetFocus
strSearch = txtSearch.Text

'If matching record found sets focus in ID and shows msgbox
'and clears search control
If strRef = strSearch Then
'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", _
, "Invalid Search Criterion!"
txtSearch.SetFocus
End If
Me.Dirty = False
End Sub

now, when i bring this form into the new form as a sub, the "DoCmd.GoToControl ("strID") comes back as cannot be found.
 
1. I don't see the need for
DoCmd.GoToControl ("strID")

2. When referring to controls in the code behind the forms they are on, you should qualify them with ME.

Example:


strRef = Me.strID.

strSearch = Me.txtSearch



And you don't need to set focus every time - IF you use the Value and not the .Text property.
 
1. I don't see the need for
DoCmd.GoToControl ("strID")

2. When referring to controls in the code behind the forms they are on, you should qualify them with ME.

Example:


strRef = Me.strID.

strSearch = Me.txtSearch



And you don't need to set focus every time - IF you use the Value and not the .Text property.
i am using the strID as a reference so the value entered in the searcg box (in the header) can reference a control in the main form thus triggering the matching IDs to be filtered in the subform. i probably just confused you with that description, sorry.

is there a way you would rewrite that coding to make it more effective?
 
i am using the strID as a reference so the value entered in the searcg box (in the header) can reference a control in the main form thus triggering the matching IDs to be filtered in the subform. i probably just confused you with that description, sorry.

is there a way you would rewrite that coding to make it more effective?

Well, not quite yet. But let's visit this part that is important. You are wanting something from the main form? If so, how are you referencing it? In code, if the code is on the subform but referencing the main form -

Me.Parent.ItemOnMainForm
 
Well, not quite yet. But let's visit this part that is important. You are wanting something from the main form? If so, how are you referencing it? In code, if the code is on the subform but referencing the main form -

Me.Parent.ItemOnMainForm
i appreciate your help, but what i have done is bypass the whole subform portion of it and just copied all the contents of the form i was going to place into the main form and pasted it, and now it all works. thanks for your help though!
 

Users who are viewing this thread

Back
Top Bottom