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 / March 2007

Tip: Looking for answers? Try searching our database.

search area on a form that opens another form with search results

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Will G - 15 Mar 2007 21:58 GMT
I have a main form that contains a Search txtbox that when cmdSearch is
click, opens another form that contains a list box of items. what i want to
do is sort this items by whatever letter is entered in the search txtbox and
when clicking a selection from the list box, go to main form and fill in the
areas with the selected item from the list box...can anyone help with this
issue?
Signature

need help

Carl Rapson - 16 Mar 2007 16:47 GMT
Each form can refer to the contents of a control on the other form. On your
popup form, pull the contents from the Search textbox to sort your list.
These newsgroups have lots of examples of referring to controls on other
forms.

For the second case, I would have the second form set a global
(application-level) variable that the first form can then pick up
immediately after the second form closes and use to locate the appropriate
record. Create a module that contains the declaration of the variable as
Public, then set the value in the Close event of the second form. Be sure to
open the second form in Dialog mode, so the first form will pause until the
second form closes.

Carl Rapson

>I have a main form that contains a Search txtbox that when cmdSearch is
> click, opens another form that contains a list box of items. what i want
[quoted text clipped - 5 lines]
> areas with the selected item from the list box...can anyone help with this
> issue?
Will G - 16 Mar 2007 17:00 GMT
Hey Carl,
i guess i am living on by ideas here man, it's there way for you to direct
me on how to do that, i am kinda new to this and i am just trying my best.  
thanks
Signature

need help

> Each form can refer to the contents of a control on the other form. On your
> popup form, pull the contents from the Search textbox to sort your list.
[quoted text clipped - 20 lines]
> > areas with the selected item from the list box...can anyone help with this
> > issue?
Will G - 16 Mar 2007 18:37 GMT
Hey Carl,
i tried this code below for filtering but it seems to give an error, can you
spot what's wrong with it....

Private Sub List0_DblClick(Cancel As Integer)

   Dim stfrmName As String
   Dim stLinkCriteria As String
   stfrmName = "MSM"
   stLinkCriteria = "[ModelNumber]=" & Me![List0]
   DoCmd.OpenForm stfrmName , , , stLinkCriteria
   DoCmd.close acForm, Me.Name, acSaveYes
End Sub

this is suppose to be the trigger even that when clicking an item from that
list box
i should be able to populate the rest of the fields on the MSM form.....but
it's giving me an error that says that OPENFORM action was canceled...what
does that mean?
Signature

need help

> Hey Carl,
> i guess i am living on by ideas here man, it's there way for you to direct
[quoted text clipped - 25 lines]
> > > areas with the selected item from the list box...can anyone help with this
> > > issue?
Carl Rapson - 19 Mar 2007 18:48 GMT
Hard to tell, but is the value in the listbox a string? If so, you need to
put quotes around the value in stLinkCriteria:

   stLinkCriteria = "[ModelNumber]='" & Me![List0] & "'"

Also, is [ModelNumber] included in your form's RecordSource? It will have to
be in order to filter this way.

Beyond that, I can't see anything.

Carl Rapson

> Hey Carl,
> i tried this code below for filtering but it seems to give an error, can
[quoted text clipped - 62 lines]
>> > > this
>> > > issue?
Will G - 19 Mar 2007 20:38 GMT
Hey Carl,
thanks for your help, i guess it does work, only that, i got a little
comfuse with what i am doing and i would love for you to clarify it for me....

i have the main form "MSM"...this form contains a search text field and i
want to enter text here, a string, and when click the search button, i want
to openup a different for that's named "frmSelectMSM" ...this form contains a
list box with ModelNumber(string and could be for example A99000M), should be
same field as the one entered in the search area txtbox.......this list box
is the only item on this form....i want to filter this list if the user
enters "A" or if the user enters the entire ModelNumber. And when i select
one of this filtered ModelNumber, i like to populate the fields on the main
form "MSM", that contains ModelNumber, and other fields. .....if you
understand this, can you help me with it?
Signature

need help

> Hard to tell, but is the value in the listbox a string? If so, you need to
> put quotes around the value in stLinkCriteria:
[quoted text clipped - 74 lines]
> >> > > this
> >> > > issue?
Carl Rapson - 19 Mar 2007 21:10 GMT
> Hey Carl,
> thanks for your help, i guess it does work, only that, i got a little
[quoted text clipped - 16 lines]
> form "MSM", that contains ModelNumber, and other fields. .....if you
> understand this, can you help me with it?
<snipped>

Let's try this again. There are two steps to this process: passing the value
from your search text field to the second form so that the listbox can be
filtered, and returning the listbox selection to the first form so it can be
used to "populate the fields" (more on this later).

For the first step, pass the value from the search text box to the second
form in the OpenArgs parameter of the FormOpen method:

DoCmd.OpenForm "frmSelectMSM",,,,,acDialog,txtSearchBox

Be sure to use your own text box control name here. We open the second form
in Dialog mode so that the first form "pauses" until the second form closes.
In the Load event of the second form, "pick up" the value from the OpenArgs
parameter and use it to filter your listbox. I can't really give an example
here, because I don't know how you are populating the listbox with the model
number strings. If the listbox is bound to a table, you can just modify the
RowSource of the listbox to incorporate the value passed in OpenArgs:

lstListBox.RowSource = "SELECT ... FROM ... WHERE [ModelNumber] LIKE '" &
OpenArgs & "*'"

I made up the name of the listbox control here, so be sure to use your
actual control name. If you are populating the listbox by some other method,
you'll need to adjust it as needed to incorporate the value in OpenArgs.

For the second step (returning the listbox selection back to the first
form), you need to first create a module to define an application-level
("global") variable that can be used from both forms. Create a new module
(or you can use an existing module if you have one) and add the variable
declaration:

Public gblSelection As String

In the second form, in the DblClick event of the listbox (or whatever other
method you use to exit the form), store the listbox selection in the global
variable:

gblSelection = lstListBox

(be sure to use your own variable and control names here). Back in the MSM
form, immediately following the OpenForm call that opened the second form,
pick up the value from the global variable and use it to "filter" the MSM
form:

Me.RecordSource = "SELECT ... FROM ... WHERE [ModelNumber]='" & gblSelection
& "'"

This assumes you're using an SQL statement for the form's RecordSource
(which is what I prefer, for just this reason). If you're using a table or
query, you may want to use the form's Filter and FilterOn properties instead
(like in your previous question). If your MSM form is unbound, you can fetch
the record from the table yourself (with a Recordset) and populate the
controls on the form.

I don't know if there's more I can add to this without actually writing the
code for you. Study these examples, look in Access and VB Help, and search
these newsgroups for specifics. What you're trying to do is fairly common
and has been addressed many times in these newsgroups.

Good luck,

Carl Rapson
Will G - 19 Mar 2007 23:37 GMT
Hey Carl thanks for the help man, but i guess i am just gonna try something
else because it's not working. the click event of the search fields it's
opening the other form but that's all it's doing. and again it might not be
something that i am not seeing since i have very little experience doing
this.  what did is this.....
Main for:
on clik
 DoCmd.OpenForm "frmSelectMSM", , , , , acDialog, TxtSearch
 Me.RecordSource = "SELECT [MSM].[ModelNumber] FROM [MSM] WHERE
[ModelNumber]='" & gblSelection & "'"

frmSelectMSM:

Private Sub SearchListBox_DblClick(Cancel As Integer)
   gblSelection = SearchListBox
End Sub

Private Sub Form_Filter(Cancel As Integer, FilterType As Integer)
SearchListBox.RowSource = "SELECT [MSM].[ModelNumber] FROM [MSM] WHERE
[ModelNumber] LIKE '" & OpenArgs & "*'"
End Sub

GLOBALMODULE:
Option Compare Database
Public gblSelection As String

frmSelectMSM:
recordsource: tblMSM

ListBox:
no control source
row source.....SELECT [MSM].[MSMID], [MSM].[ModelNumber] FROM [MSM];
Signature

need help

> > Hey Carl,
> > thanks for your help, i guess it does work, only that, i got a little
[quoted text clipped - 80 lines]
>
> Carl Rapson
Carl Rapson - 20 Mar 2007 16:15 GMT
In frmSelectMSM, you need to set SearchListBox.RowSource in the Form_Load
event, not the Form_Filter event.

Carl Rapson

> Hey Carl thanks for the help man, but i guess i am just gonna try
> something
[quoted text clipped - 137 lines]
>>
>> Carl Rapson
Will G - 20 Mar 2007 16:48 GMT
Hey Carl
again thanks for your help and for being patient with me....i did what you
told me, got the searchListBox.Rowsource at the load even of the
frmSelectMSM, but it doesnt work, all it does is open the form and this time,
the list shows no record. i have it set up just as stated in the previous
post and with the change that you just suggested and still dont load with
ModelNumbers sorted. any further suggestion?
Signature

need help

> In frmSelectMSM, you need to set SearchListBox.RowSource in the Form_Load
> event, not the Form_Filter event.
[quoted text clipped - 142 lines]
> >>
> >> Carl Rapson
Carl Rapson - 22 Mar 2007 16:49 GMT
Sorry, I'm fresh out of ideas. Based on what you've given me, I don't see
anything else to try.

Carl Rapson

> Hey Carl
> again thanks for your help and for being patient with me....i did what you
[quoted text clipped - 47 lines]
>> > no control source
>> > row source.....SELECT [MSM].[MSMID], [MSM].[ModelNumber] FROM [MSM];

<snipped>
 
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.