Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 1 / December 2005

Tip: Looking for answers? Try searching our database.

error setting a subforms recordsource from another form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bex - 13 Dec 2005 16:37 GMT
Hi All.

I'm attempting at the moment to set the recordsource of an unbound
subform when i open up it's main form.

My view is to have one intial form - called "Search" which has a number
of unbound textboxes. When a user enters in a value into a field and
hits the search button this opens up a results form called "people3"
and sets a subform in this "people3" form - called "results" to show
certain records matching the entered search criteria. The Subform is
initially unbound.

So far i have this code on the search form (only one search field so
far but will be more eventually):

Private Sub cmdFirst_Click()
On Error GoTo Err_cmdFirst_Click

   Dim stDocName As String
   Dim stLinkCriteria As String
   Dim message
   Dim strSQL, strWHERE As String

   stDocName = "People3"
   strSQL = "SELECT DISTINCTROW People.* FROM People "

   If Not IsNull(Me.FirstName) Then
       strWHERE = " WHERE People.[FirstName] Like " & "'*" &
Me![FirstName] & "*'"
   End If

   strSQL = strSQL & strWHERE

   If Len(strWHERE) = 0 Then
       message = MsgBox("No search values entered")
   Else
       DoCmd.OpenForm stDocName
       Forms![People3]![Results].Form.RecordSource = strSQL
   End If

Exit_cmdFirst_Click:
   Exit Sub

Err_cmdFirst_Click:
   MsgBox Err.Description
   Resume Exit_cmdFirst_Click

End Sub

Which is opening up the form but I keep getting the error of: "the
expression you entered refers to an object that is closed or doesn't
exist"

So what am i doing wrong?!?!
Cheers
Bex
Allen Browne - 14 Dec 2005 02:19 GMT
Could you save your subform with a RecordSource that returns no records:
   SELECT People.* FROM People WHERE (False);

That should keep Access happy about the bound controls in the subform.

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> Hi All.
>
[quoted text clipped - 52 lines]
> Cheers
> Bex
Bex - 14 Dec 2005 09:42 GMT
Thanks Allen... that seems t have sorted it - or certainly got it to a
point where hopefully i can get the other bits to work! :)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.