Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filling A List Box

Status
Not open for further replies.

accessuserva

Technical User
Aug 7, 2002
26
US
I have a form with a list box in it to be filled with data after a guery is run from the form

Private Sub Search_Radius_Exit(Cancel As Integer)
Dim stDocName As String

stDocName = "qrySitedistance"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_Command212_Click:
Exit Sub

this is what I have... the problem is the data is not filling the list box. The query runs fine and I have
made the row source of the list box the data that I want in the list box from the query..Do I need to put in code to tell access to fill the form after the query is run.

I have very limited vb experience and my teacher was of no help either as VB is not is cup of tea.

Thanks.

 
Hi,

You should set the RowSource property of the list box to the query. Try the following in your procedure:

Private Sub SearchRadius_Exit()
Me.List1.RowSourceType="Table/Query"
Me.List1.RowSource="qrySiteDistance"
Me.List1.Requery
End Sub

Hope this helps. Let me know what happens.


With regards,
PGK
 
where do I put that into?..the query runs after I enter A distance into a text box..with the list box (hopefully) filling up with the results

For the list box to be filled I have this already

Controlsource=sitename
Row Source Type=Table/Query
Row Source=qrySitedistance


Listbox Name=searchresults

THanks
 
Hi,
What you seem to have is a parametrized query. What is the purpose of your query? I will take a sample query in which all employees who live in a particular area are displayed in a list box. Here I have used SQL to get the data.

Option Compare Database

Private Sub Command4_Click()
If Nz(Me.Text0) <> &quot;&quot; Then
Me.List2.RowSource = &quot;Select name from Table6 where area='&quot; & Me.Text0 & &quot;'&quot;
Me.List2.Requery
Else
MsgBox &quot;Please enter area&quot;
End If
End Sub

The user types in the area name and clicks on the command button to populate the list with the names of the employees living in that area.

If you could tell me what is the purpose of your query, I may be able to help you better. Post again if you want any help.

With regards,
PGK
 
I work for an engineering firm that is currently doing Telco site design..One of my tables has lat & long info on each site we have done. The query looks at the site chosen in the form, which is automatically filled in based on what site numnber you choose then it takes the search radius (which is the only variable that you really have to input) and gives you any and/or all sites that fall within the search radius range based on the lats & longs. Like I said the query runs fine because it pops up in front of the form with the correct info in it so I know that part works.

If you would like I could send you the file for you to take a look at it might be easier that way

 
Hi,
Since you say that the query is working fine as such, try the following:

In the criteria of the query, refer to the particular control that contains the search radius as below:

Ex. =[Forms]![Your Form Name].[Name of Control that contains Search Rdaius]

The = sign is important in the criteria.

Set the RowSource property of the list box to the query and requery it.

Me.List1.RowSource=&quot;qrySiteDistance&quot;
Me.List1.Requery

In case it does not help, just send me your file to the following id:

pgk1979@rediffmail.com




With regards,
PGK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top