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 / Forms Programming / July 2005

Tip: Looking for answers? Try searching our database.

Go to matching record from one subform to another

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kurt - 24 Jul 2005 22:18 GMT
I have an unbound main form (frmProjects) with several tabs: Home, Studies,
Manuscripts, etc. Each tab has a different subform. On the Studies tab is a
subform (fsubStudies) which shows studies; on the Manuscripts tab is a
subform (fsubManuscripts) which shows manuscripts, etc. On the Home tab is a
continuous subform (fsubProjectList) which shows a list of all Projects.

See screenshot: http://members.cox.net/kheisler6/frmProjects.jpg

I would like to click on a project listed on the Home tab’s ProjectList
subform and move the focus to the appropriate subform (one on of several
tabs) and the appropriate record on the subform. For example, when the user
clicks a project on the fsubProjectList:

- If ProjectType = “Study,” go to the Studies tab and go to the appropriate
record (i.e., with matching ProjectID) on the Study subform.

- If ProjectType = “Manuscript,” go to the Manuscript tab and go to the
appropriate record (i.e., with matching ProjectID) on the Manuscript subform.

And so forth.

I tried putting code in the On Click event of the ProjectTitle which sets
the focus to the appropriate tab/subform and then finds the matching record:

###

Private Sub ProjectTitle_Click()
   If Me.ProjectTypeID.Value = "Study" Then
       ' set focus on subform/tab
       Me.Parent!pgStudies.SetFocus
       ' go to matching record
        Me.DoCmd.OpenForm "fsubStudies", , , "[ProjectID] = " &
Forms![fsubProjectList]![ProjectID]
   ElseIf Me.ProjectTypeID.Value = "Manuscript" Then
       '...
   End If

###

But this gives me a Compile error: Method or data member not found, which
highlights the last  [ProjectID] in the main SQL statement.

What am I doing wrong? Thanks.

- Kurt
Graham Mandeno - 24 Jul 2005 22:51 GMT
Hi Kurt

You are getting the error because DoCmd is a method of the Application
object, not "Me" (which in this scope is a Form object).

In any case, DoCmd.OpenForm is not what you need, because that would open a
new, independent instance of "fsubStudies" as a *main* form.  Thi instance
that you want to refer to is already open, contained in the subform control.

Try this:

   Dim strCtlName as string
   Dim sbfrm as Form
' first identify the correct subform control
   Select case Me.ProjectType
       case "Study"
           strCtlName = "fsubStudies"
' name of the subform *control* which contains the Studies subform
       case "Manuscript"
           strCtlName = "fsubManuscripts"
       ' etc...
   End Select
' now set focus to the subform control and reference the contained form
   With Me.Parent(strCtlName)
       .SetFocus
       Set sbfrm = .Form
   End With
' now find the desired record
   With sbfrm.RecordsetClone
       .FindFirst "[ProjectID] = " & Me.ProjectID
       If not .NoMatch then sbfrm.Bookmark = .Bookmark
   End With

This assumes that the primary key field of each of the subforms' recordsets
is named "ProjectID".  If not, you will need to set an additional variable
in the case statement to the name of the key field.
Signature

Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

>I have an unbound main form (frmProjects) with several tabs: Home, Studies,
> Manuscripts, etc. Each tab has a different subform. On the Studies tab is
[quoted text clipped - 47 lines]
>
> - Kurt
 
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.