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 / April 2005

Tip: Looking for answers? Try searching our database.

Refer to subform

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Snowsride - 29 Apr 2005 12:36 GMT
I have a Main form with two subforms Sub1 and Sub2.

I want to set the RecordSource of Sub2 from the OnGotfocus event on Control1
on Sub1.

My code is:

Dim intCtrl as integer
Dim strSQL as string

intCtrl = Me.Control1
strSQL = "Select * from MyTable where Id = " & strSQL
Forms!Main!Form!Sub2.RecordSource = strSQL
Forms!Main!Form!Sub2.RecordSource.ReQuery

When Control1 gets the focus I get an error Runtime error 2465 Access can't
find the field 'Form' referred in your expression.

Have tried many permutations but no luck.

Grateful for help.
David W - 29 Apr 2005 13:02 GMT
Try this
Forms!Main.Form!Sub2.RecordSource = strSQL
Forms!Main.Form!Sub2.RecordSource.ReQuery

instead of

Forms!Main!Form!Sub2.RecordSource = strSQL
Forms!Main!Form!Sub2.RecordSource.ReQuery

>I have a Main form with two subforms Sub1 and Sub2.
>
[quoted text clipped - 19 lines]
>
> Grateful for help.
Snowsride - 29 Apr 2005 13:18 GMT
Different error now!

Access can't find the field Sub2 referred to.

> Try this
> Forms!Main.Form!Sub2.RecordSource = strSQL
[quoted text clipped - 28 lines]
> >
> > Grateful for help.
tina - 29 Apr 2005 13:44 GMT
if i understand you correctly, both subforms (1 and 2) are on the open main
form, and Control1 is a control on the Sub1 subform. first, i think your
strSQL line should be

   strSQL = "Select * from MyTable where Id = " & intCtrl

and try the next two lines as

   Me.Parent!Sub2.Form.RecordSource = strSQL
   Me.Parent!Sub2.Form.Requery

since you're running the code from the GotFocus event of Control1, keep in
mind that if there's no value in the control when it gets the focus, your
code will at best give you no results, and at worst will err out.

other than that, just make sure that Sub2 is the name of the subform
*control* within the main form (the subform control name *may* be different
than the name of the subform).

hth

> Different error now!
>
[quoted text clipped - 32 lines]
> > >
> > > Grateful for help.
 
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.