PC Review


Reply
Thread Tools Rate Thread

Change the recordsource of a subform that is on an unbound main fo

 
 
Debbie
Guest
Posts: n/a
 
      17th Jan 2008
Hello all,
I know there are many appends on this but I just can't get this to work.

I have an unbound main form (Main). On it are several subforms. The first
subform (Vehicle) contains a summary of the vehicles. When I click on one of
the vehicles, I would like the second subform (Vehicle Allocation History) to
display records for the vehicle selected in the Vehicle form. Below is my
code:

Dim VehAlloc As Control
Dim Main As Form
Dim VIN As String
Dim SQL As String

Set Main = Forms("VehicleSummaryForm")
Set VehAlloc = Main.VehicleAllocationHistory
VIN = Me!VIN
SQL = "SELECT * FROM Vehicle WHERE VIN = '" & VIN & "'"
VehAlloc.Form.RecordSource = SQL

I keep getting an error saying that I'm making an invalid reference. I have
tried the Parent property, fully qualifying form names and other stuff which
is now all a blur. I also tried the statement VehAlloc.Recordsource = SQL
but that didn't work. Does any one have any idea as to why this won't work?
Any suggestions would be most appreciated. Thanks in advance.
Debbie
 
Reply With Quote
 
 
 
 
Arvin Meyer [MVP]
Guest
Posts: n/a
 
      17th Jan 2008
Dim strSQL As String
strSQL = "SELECT * FROM Vehicle WHERE VIN = '" & txtVIN & "'"
Me.NameOfSubform.Recordsource = strSQL

You may have a problem with ambiguous naming of VIN, so it would be wise to
name the textbox txtVIN.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

"Debbie" <(E-Mail Removed)> wrote in message
news:92846A60-907F-4768-8D9A-(E-Mail Removed)...
> Hello all,
> I know there are many appends on this but I just can't get this to work.
>
> I have an unbound main form (Main). On it are several subforms. The
> first
> subform (Vehicle) contains a summary of the vehicles. When I click on one
> of
> the vehicles, I would like the second subform (Vehicle Allocation History)
> to
> display records for the vehicle selected in the Vehicle form. Below is my
> code:
>
> Dim VehAlloc As Control
> Dim Main As Form
> Dim VIN As String
> Dim SQL As String
>
> Set Main = Forms("VehicleSummaryForm")
> Set VehAlloc = Main.VehicleAllocationHistory
> VIN = Me!VIN
> SQL = "SELECT * FROM Vehicle WHERE VIN = '" & VIN & "'"
> VehAlloc.Form.RecordSource = SQL
>
> I keep getting an error saying that I'm making an invalid reference. I
> have
> tried the Parent property, fully qualifying form names and other stuff
> which
> is now all a blur. I also tried the statement VehAlloc.Recordsource = SQL
> but that didn't work. Does any one have any idea as to why this won't
> work?
> Any suggestions would be most appreciated. Thanks in advance.
> Debbie



 
Reply With Quote
 
 
 
 
Debbie
Guest
Posts: n/a
 
      17th Jan 2008
Arvin,
Thank you for such a quick response! I did change the name of the text box
but I got a different error. It is from the statement:
Me.NameOfSubform.Recordsource = strSQL

With the syntax you gave me, it looks like code that would run on the main
form. I need the code to run from within the subform Vehicle and based on
the current row there, requery another subform on this screen called Vehicle
Allocation History. The main form is unbound. (I'm sure this late hour
isn't helping either of us!)
Do you see what I mean? Thanks,
Debbie

"Arvin Meyer [MVP]" wrote:

> Dim strSQL As String
> strSQL = "SELECT * FROM Vehicle WHERE VIN = '" & txtVIN & "'"
> Me.NameOfSubform.Recordsource = strSQL
>
> You may have a problem with ambiguous naming of VIN, so it would be wise to
> name the textbox txtVIN.
> --
> Arvin Meyer, MCP, MVP
> http://www.datastrat.com
> http://www.mvps.org/access
> http://www.accessmvp.com
>
> "Debbie" <(E-Mail Removed)> wrote in message
> news:92846A60-907F-4768-8D9A-(E-Mail Removed)...
> > Hello all,
> > I know there are many appends on this but I just can't get this to work.
> >
> > I have an unbound main form (Main). On it are several subforms. The
> > first
> > subform (Vehicle) contains a summary of the vehicles. When I click on one
> > of
> > the vehicles, I would like the second subform (Vehicle Allocation History)
> > to
> > display records for the vehicle selected in the Vehicle form. Below is my
> > code:
> >
> > Dim VehAlloc As Control
> > Dim Main As Form
> > Dim VIN As String
> > Dim SQL As String
> >
> > Set Main = Forms("VehicleSummaryForm")
> > Set VehAlloc = Main.VehicleAllocationHistory
> > VIN = Me!VIN
> > SQL = "SELECT * FROM Vehicle WHERE VIN = '" & VIN & "'"
> > VehAlloc.Form.RecordSource = SQL
> >
> > I keep getting an error saying that I'm making an invalid reference. I
> > have
> > tried the Parent property, fully qualifying form names and other stuff
> > which
> > is now all a blur. I also tried the statement VehAlloc.Recordsource = SQL
> > but that didn't work. Does any one have any idea as to why this won't
> > work?
> > Any suggestions would be most appreciated. Thanks in advance.
> > Debbie

>
>
>

 
Reply With Quote
 
n00b
Guest
Posts: n/a
 
      17th Jan 2008
I think you are going down the wrong path. A better approach would be to
place an unbound textbox on the Main form, call it txtVIN (set its visible
property to false.)

Then add one line of code the Vehicle subform in its Current event:

Private Sub Form_Current()

Parent.txtVIN= VIN

End Sub

Then in the history subform's properties, link the child and master fields
using the textbox as you would a field name in a table:

Link Child Fields = VIN
Link Master Fields = txtVIN

Not whenever you "select" a vehicle in the vehicle subform, the txtVIN will
contain the VIN of the Vehicle and the child/master linking will
automatically requery the history subform using the value in txtVIN. This is
one of the really nice features of Microsoft Access!

Please note:
I am assuming the Vehicle table has a VIN field and the Vehicle Allocation
History table has a VIN field.



"Debbie" wrote:

> Hello all,
> I know there are many appends on this but I just can't get this to work.
>
> I have an unbound main form (Main). On it are several subforms. The first
> subform (Vehicle) contains a summary of the vehicles. When I click on one of
> the vehicles, I would like the second subform (Vehicle Allocation History) to
> display records for the vehicle selected in the Vehicle form. Below is my
> code:
>
> Dim VehAlloc As Control
> Dim Main As Form
> Dim VIN As String
> Dim SQL As String
>
> Set Main = Forms("VehicleSummaryForm")
> Set VehAlloc = Main.VehicleAllocationHistory
> VIN = Me!VIN
> SQL = "SELECT * FROM Vehicle WHERE VIN = '" & VIN & "'"
> VehAlloc.Form.RecordSource = SQL
>
> I keep getting an error saying that I'm making an invalid reference. I have
> tried the Parent property, fully qualifying form names and other stuff which
> is now all a blur. I also tried the statement VehAlloc.Recordsource = SQL
> but that didn't work. Does any one have any idea as to why this won't work?
> Any suggestions would be most appreciated. Thanks in advance.
> Debbie

 
Reply With Quote
 
Arvin Meyer [MVP]
Guest
Posts: n/a
 
      18th Jan 2008
Yes, you need to use your own subform's name not NameOfSubform.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

"Debbie" <(E-Mail Removed)> wrote in message
news:8DB66BDD-E8DA-4942-B729-(E-Mail Removed)...
> Arvin,
> Thank you for such a quick response! I did change the name of the text
> box
> but I got a different error. It is from the statement:
> Me.NameOfSubform.Recordsource = strSQL
>
> With the syntax you gave me, it looks like code that would run on the main
> form. I need the code to run from within the subform Vehicle and based on
> the current row there, requery another subform on this screen called
> Vehicle
> Allocation History. The main form is unbound. (I'm sure this late hour
> isn't helping either of us!)
> Do you see what I mean? Thanks,
> Debbie
>
> "Arvin Meyer [MVP]" wrote:
>
>> Dim strSQL As String
>> strSQL = "SELECT * FROM Vehicle WHERE VIN = '" & txtVIN & "'"
>> Me.NameOfSubform.Recordsource = strSQL
>>
>> You may have a problem with ambiguous naming of VIN, so it would be wise
>> to
>> name the textbox txtVIN.
>> --
>> Arvin Meyer, MCP, MVP
>> http://www.datastrat.com
>> http://www.mvps.org/access
>> http://www.accessmvp.com
>>
>> "Debbie" <(E-Mail Removed)> wrote in message
>> news:92846A60-907F-4768-8D9A-(E-Mail Removed)...
>> > Hello all,
>> > I know there are many appends on this but I just can't get this to
>> > work.
>> >
>> > I have an unbound main form (Main). On it are several subforms. The
>> > first
>> > subform (Vehicle) contains a summary of the vehicles. When I click on
>> > one
>> > of
>> > the vehicles, I would like the second subform (Vehicle Allocation
>> > History)
>> > to
>> > display records for the vehicle selected in the Vehicle form. Below is
>> > my
>> > code:
>> >
>> > Dim VehAlloc As Control
>> > Dim Main As Form
>> > Dim VIN As String
>> > Dim SQL As String
>> >
>> > Set Main = Forms("VehicleSummaryForm")
>> > Set VehAlloc = Main.VehicleAllocationHistory
>> > VIN = Me!VIN
>> > SQL = "SELECT * FROM Vehicle WHERE VIN = '" & VIN & "'"
>> > VehAlloc.Form.RecordSource = SQL
>> >
>> > I keep getting an error saying that I'm making an invalid reference. I
>> > have
>> > tried the Parent property, fully qualifying form names and other stuff
>> > which
>> > is now all a blur. I also tried the statement VehAlloc.Recordsource =
>> > SQL
>> > but that didn't work. Does any one have any idea as to why this won't
>> > work?
>> > Any suggestions would be most appreciated. Thanks in advance.
>> > Debbie

>>
>>
>>



 
Reply With Quote
 
Debbie
Guest
Posts: n/a
 
      18th Jan 2008
Thank you both so much. The main/subform idea worked great. I actually had
that at one point but discarded because I thought both the main form had to
be bound. This is really valuable stuff! Thanks so much!
Debbie

"n00b" wrote:

> I think you are going down the wrong path. A better approach would be to
> place an unbound textbox on the Main form, call it txtVIN (set its visible
> property to false.)
>
> Then add one line of code the Vehicle subform in its Current event:
>
> Private Sub Form_Current()
>
> Parent.txtVIN= VIN
>
> End Sub
>
> Then in the history subform's properties, link the child and master fields
> using the textbox as you would a field name in a table:
>
> Link Child Fields = VIN
> Link Master Fields = txtVIN
>
> Not whenever you "select" a vehicle in the vehicle subform, the txtVIN will
> contain the VIN of the Vehicle and the child/master linking will
> automatically requery the history subform using the value in txtVIN. This is
> one of the really nice features of Microsoft Access!
>
> Please note:
> I am assuming the Vehicle table has a VIN field and the Vehicle Allocation
> History table has a VIN field.
>
>
>
> "Debbie" wrote:
>
> > Hello all,
> > I know there are many appends on this but I just can't get this to work.
> >
> > I have an unbound main form (Main). On it are several subforms. The first
> > subform (Vehicle) contains a summary of the vehicles. When I click on one of
> > the vehicles, I would like the second subform (Vehicle Allocation History) to
> > display records for the vehicle selected in the Vehicle form. Below is my
> > code:
> >
> > Dim VehAlloc As Control
> > Dim Main As Form
> > Dim VIN As String
> > Dim SQL As String
> >
> > Set Main = Forms("VehicleSummaryForm")
> > Set VehAlloc = Main.VehicleAllocationHistory
> > VIN = Me!VIN
> > SQL = "SELECT * FROM Vehicle WHERE VIN = '" & VIN & "'"
> > VehAlloc.Form.RecordSource = SQL
> >
> > I keep getting an error saying that I'm making an invalid reference. I have
> > tried the Parent property, fully qualifying form names and other stuff which
> > is now all a blur. I also tried the statement VehAlloc.Recordsource = SQL
> > but that didn't work. Does any one have any idea as to why this won't work?
> > Any suggestions would be most appreciated. Thanks in advance.
> > Debbie

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
unbound subform on unbound form: getting data into subform EVPLS Microsoft Access Form Coding 1 19th Jan 2008 07:09 PM
set recordsource of subform from main form Paul Doree Microsoft Access Form Coding 1 13th Sep 2005 09:12 PM
Setting RecordSource of a Subform based on text fields on main form. Satadru Sengupta Microsoft Access Form Coding 1 26th Oct 2004 09:02 AM
SubForm Modify of "RecordSource" on User action on main form =?Utf-8?B?c2hhZA==?= Microsoft Access Form Coding 1 19th Oct 2004 05:40 AM
Re: How To: Change the recordsource of a subform of a subform Marshall Barton Microsoft Access Form Coding 3 20th Sep 2003 03:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:28 PM.