A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Continuous Form and subform - Linking with List Box help



 
 
Thread Tools Display Modes
  #1  
Old December 14th, 2005, 10:25 AM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default Continuous Form and subform - Linking with List Box help

Hi, I am trying to recreate the search for groups form he
http://www.members.shaw.ca/AlbertKal...icles/Grid.htm . So far I have an
unbound form with a listbox on the left and a continuous subform on the
right. My two problems a 1. How do I open the form so that the listbox
is filtered on a value from the previous form. 2. How do I bound my subform
on the right do the listbox?

Thanks in advance


  #2  
Old December 15th, 2005, 02:14 AM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default Continuous Form and subform - Linking with List Box help

I been so busy..and just not able to post a decent sample.

however, lets post some of the code I used


1. How do I open the form so that the listbox is filtered on a value from
the previous form.


Well, in my case, I had a text box at the top, and user just typed in a few
characters and hit enter to fill the lisbox.

However, lets assume your case of wanting to load up the listbox when the
form loads with a passed filter. You don't mention what particular filter,
but lets just assume it is a particular "id", or some condition?. You can
either open the form up, and then set the list box.

Like:
dim strF as string
dim strSql as string

strF = "OurCoolSearchForm"
docmd.Open strF
strSql = "select * from tblForListbox where id = " & me!id
forms(strF)!TheListBoxOnTheLeftSide.RowSource = strSql

or, you could even use the forms filter

strSql = "select * from tblForListbox where " & me.filter
forms(strF)!TheListBoxOnTheLeftSide.RowSource = strSql

Another approach is to just pass the value needed, So,

dim strF as string
dim strSql as string


strF = "OurCoolSearchForm"
docmd.Open strF, , , , ,me!id

In the fomrs on-load event, you go

me.TheListBoxOnTheLeftSide.RowSource =
"select * from tblFrListBos where id = " & me.OpenArgs

(the above would be on one line)

2. How do I bound my subform
on the right do the listbox?


Well, actually, could use two sub-forms, and not much code..but my exmaple
is a listbox
So, I use the after update event of the listbox (when you change it..the
after update event fires).

The code in hte after update event looks like

Dim subSql As String

If IsNull(Me.List51) = False Then
If Me.List51 "" Then
subSql = "SELECT GroupName, TripDate, Seats, Destination, Hotel"
subSql = subSql & " FROM OldGroupTrips WHERE [Gid] = " & Me.List51
subSql = subSql & " order by TripDate DESC"
Me.OldGroupTrips_subform.Form.RecordSource = subSql
Me.OldGroupTrips_subform.Visible = True
End If
End If

Now, I likely should have built a query and used hat above..but it don't
matter.

Note that you also need to fill the right side right after you load up the
list box. So, here the code that *really* should go in the on-load event

Me.List51.RowSource = "select * from tblForListBos where id = " &
me.OpenArgs
Me.List51.SetFocus

Me.List51.Selected(1) = True
Me.List51 = Me.List51.Column(0)

Call List51_AfterUpdate

That is nut shell as to how this works....


--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada

http://www.members.shaw.ca/AlbertKallal


  #3  
Old December 15th, 2005, 02:48 PM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default Continuous Form and subform - Linking with List Box help

Thanks very much for posting - Extremely helpful!



"Albert D.Kallal" wrote in message
...
I been so busy..and just not able to post a decent sample.

however, lets post some of the code I used


1. How do I open the form so that the listbox is filtered on a value from
the previous form.


Well, in my case, I had a text box at the top, and user just typed in a
few characters and hit enter to fill the lisbox.

However, lets assume your case of wanting to load up the listbox when the
form loads with a passed filter. You don't mention what particular filter,
but lets just assume it is a particular "id", or some condition?. You can
either open the form up, and then set the list box.

Like:
dim strF as string
dim strSql as string

strF = "OurCoolSearchForm"
docmd.Open strF
strSql = "select * from tblForListbox where id = " & me!id
forms(strF)!TheListBoxOnTheLeftSide.RowSource = strSql

or, you could even use the forms filter

strSql = "select * from tblForListbox where " & me.filter
forms(strF)!TheListBoxOnTheLeftSide.RowSource = strSql

Another approach is to just pass the value needed, So,

dim strF as string
dim strSql as string


strF = "OurCoolSearchForm"
docmd.Open strF, , , , ,me!id

In the fomrs on-load event, you go

me.TheListBoxOnTheLeftSide.RowSource =
"select * from tblFrListBos where id = " & me.OpenArgs

(the above would be on one line)

2. How do I bound my subform
on the right do the listbox?


Well, actually, could use two sub-forms, and not much code..but my exmaple
is a listbox
So, I use the after update event of the listbox (when you change it..the
after update event fires).

The code in hte after update event looks like

Dim subSql As String

If IsNull(Me.List51) = False Then
If Me.List51 "" Then
subSql = "SELECT GroupName, TripDate, Seats, Destination, Hotel"
subSql = subSql & " FROM OldGroupTrips WHERE [Gid] = " & Me.List51
subSql = subSql & " order by TripDate DESC"
Me.OldGroupTrips_subform.Form.RecordSource = subSql
Me.OldGroupTrips_subform.Visible = True
End If
End If

Now, I likely should have built a query and used hat above..but it don't
matter.

Note that you also need to fill the right side right after you load up the
list box. So, here the code that *really* should go in the on-load event

Me.List51.RowSource = "select * from tblForListBos where id = " &
me.OpenArgs
Me.List51.SetFocus

Me.List51.Selected(1) = True
Me.List51 = Me.List51.Column(0)

Call List51_AfterUpdate

That is nut shell as to how this works....


--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada

http://www.members.shaw.ca/AlbertKallal




 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to show both "Yes" and "No" answers from a "yes/no" checkbox? Colin Foster New Users 28 March 18th, 2005 02:19 PM
Dates in a listbox connected to a form... RusCat Using Forms 13 November 25th, 2004 02:31 AM
open a form through a subform in access 2000 Tammy Setting Up & Running Reports 12 October 22nd, 2004 02:43 PM
Continuous Subform / Form - Orphan records Rich J Using Forms 6 October 15th, 2004 08:59 PM
dlookup miaplacidus Using Forms 9 August 5th, 2004 09:16 PM


All times are GMT +1. The time now is 11:55 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.