473,414 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Displaying Results from a Query using a Form

kmartinenko
Hello,

I am in need of some serious help with my Access 2000 database.

I have created a form with two combo boxes: stops_combo and stoptime_combo. When a bus stop is selected from stops_combo, the stoptime_combo box is populated with the stop times for the stop selected.
I've got that down, and it seems to work fine.

Now, I want to create a new table out of these selections. Ideally, I want to be able to click on a command button and up will pop a new table displaying the stop and stop times associated with that stop.

I am assuming that I need to somehow link up an SQL statement to a DoCmd in VBA, but I am not sure how to do it.

I am very new to VBA...I feel like I know just enough that I am stuck in a rut and trying to figure this out is driving me crazy! :-)

Thanks,

Kindra
Jan 10 '08 #1
5 2095
Dököll
2,364 Expert 2GB
Hello,

I am in need of some serious help with my Access 2000 database.

I have created a form with two combo boxes: stops_combo and stoptime_combo. When a bus stop is selected from stops_combo, the stoptime_combo box is populated with the stop times for the stop selected.
I've got that down, and it seems to work fine.

Now, I want to create a new table out of these selections. Ideally, I want to be able to click on a command button and up will pop a new table displaying the stop and stop times associated with that stop.

I am assuming that I need to somehow link up an SQL statement to a DoCmd in VBA, but I am not sure how to do it.

I am very new to VBA...I feel like I know just enough that I am stuck in a rut and trying to figure this out is driving me crazy! :-)

Thanks,

Kindra
Hello, Kindra!

Are you able to post some of your coding for a closer look?

I have some ideas, perhaps other experts here, I am trying not to spin my wheels trying to give you the good word. Post a portion of the code, at least what is not working or what you hope to achieve, we'll have a look:-)

Just like you, I am new to VBA, still I assume it is pretty simple perhaps your code can help shed some light...

In a bit!
Jan 11 '08 #2
Hello, Kindra!

Are you able to post some of your coding for a closer look?

I have some ideas, perhaps other experts here, I am trying not to spin my wheels trying to give you the good word. Post a portion of the code, at least what is not working or what you hope to achieve, we'll have a look:-)

Just like you, I am new to VBA, still I assume it is pretty simple perhaps your code can help shed some light...

In a bit!
Okay, the only code I have thus far is in SQL and AfterUpdate code in VBA for the first combo box.

Here is what the VBA code looks like for the first combo box, stops_combo:

Expand|Select|Wrap|Line Numbers
  1. Private Sub stops_combo_AfterUpdate()
  2. Me.stoptime_combo.Requery
  3. End Sub
And the SQL Statement in the Rowsource for the stops_combo box is simply:
Expand|Select|Wrap|Line Numbers
  1. SELECT stopquery.STOP
  2. FROM stopquery;
  3.  
For the second combo box stoptime_combo I have a the following SQL in the Rowsource:
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT [Rte1stoptimes].[STRTIME] FROM Rte1stoptimes WHERE ((([Rte1stoptimes].[STOP])=[Forms]![RouteInfo]![stops_combo])) ORDER BY [Rte1stoptimes].[STRTIME] DESC; 
Again, after the selections have been made from stops_combo and stoptimes_combo, I want to be able to click a command button that generates a new table showing the search results from the selections made. Thanks in advance for the help!

--Kindra
Jan 11 '08 #3
zaidlig
45
Okay, the only code I have thus far is in SQL and AfterUpdate code in VBA for the first combo box.

Here is what the VBA code looks like for the first combo box, stops_combo:

Expand|Select|Wrap|Line Numbers
  1. Private Sub stops_combo_AfterUpdate()
  2. Me.stoptime_combo.Requery
  3. End Sub
And the SQL Statement in the Rowsource for the stops_combo box is simply:
Expand|Select|Wrap|Line Numbers
  1. SELECT stopquery.STOP
  2. FROM stopquery;
  3.  
For the second combo box stoptime_combo I have a the following SQL in the Rowsource:
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT [Rte1stoptimes].[STRTIME] FROM Rte1stoptimes WHERE ((([Rte1stoptimes].[STOP])=[Forms]![RouteInfo]![stops_combo])) ORDER BY [Rte1stoptimes].[STRTIME] DESC; 
Again, after the selections have been made from stops_combo and stoptimes_combo, I want to be able to click a command button that generates a new table showing the search results from the selections made. Thanks in advance for the help!

--Kindra
I would create and save a simple "query1" doesn't matter whats in it.
then add this code to your second combo box event:

CurrentDb.QueryDefs("Query1").SQL = "SELECT DISTINCT [Rte1stoptimes].[STRTIME] FROM Rte1stoptimes WHERE ((([Rte1stoptimes].[STOP])=[Forms]![RouteInfo]![stops_combo])) ORDER BY [Rte1stoptimes].[STRTIME] DESC; "

then add this to you command button click event:
DoCmd.OpenQuery "Query1", acViewNormal

There are other ways to do this but creating a saved query is the best if you later decide you want a report and another form to use the same data.
Jan 11 '08 #4
I would create and save a simple "query1" doesn't matter whats in it.
then add this code to your second combo box event:

CurrentDb.QueryDefs("Query1").SQL = "SELECT DISTINCT [Rte1stoptimes].[STRTIME] FROM Rte1stoptimes WHERE ((([Rte1stoptimes].[STOP])=[Forms]![RouteInfo]![stops_combo])) ORDER BY [Rte1stoptimes].[STRTIME] DESC; "

then add this to you command button click event:
DoCmd.OpenQuery "Query1", acViewNormal

There are other ways to do this but creating a saved query is the best if you later decide you want a report and another form to use the same data.
Thank you for this explanation! This is getting *close* to what I am after, except that I want all fields to be displayed from the Rte1stoptimes table for both the stop and stop time selected from the combo boxes...but I think I can tailor the code above to meet those specs. It was the CurrentDb.QueryDefs("Query1").SQL statement that I was looking for...

Many thanks!
Jan 11 '08 #5
I would create and save a simple "query1" doesn't matter whats in it.
then add this code to your second combo box event:

CurrentDb.QueryDefs("Query1").SQL = "SELECT DISTINCT [Rte1stoptimes].[STRTIME] FROM Rte1stoptimes WHERE ((([Rte1stoptimes].[STOP])=[Forms]![RouteInfo]![stops_combo])) ORDER BY [Rte1stoptimes].[STRTIME] DESC; "

then add this to you command button click event:
DoCmd.OpenQuery "Query1", acViewNormal

There are other ways to do this but creating a saved query is the best if you later decide you want a report and another form to use the same data.
Update:

SUCCESS!!! I modified the above CurrentDb.QueryDefs code to return all records matching the combo box selections and it worked perfectly. Thanks again for all of your help! This made my Friday a lot happier!
Jan 11 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: jaysonsch | last post by:
Hello! I am having some problems with a database query that I am trying to do. I am trying to develop a way to search a database for an entry and then edit the existing values. Upon submit, the...
6
by: Matt K. | last post by:
Hi there, I have a form in an Access project that contains a subform which displays the results of a query of the style "select * from where = #a certain date#". In the main part of the form...
2
by: Greg Bale | last post by:
Hi. (this is s repeat post from MS community newsgroup) I am building a form for people to use to analyse the data in my Access2000 database. The SQL is built up in VBA depending on control...
6
by: Stuart Clark | last post by:
Hiya I'm learning ASP using Access and Dreamweaver. I've just started simple and I've tried to make the db show the results of just two tables without doing anything clever! I have the following...
7
by: Joe | last post by:
I am using Access 2003 and are linking to an Oracle 9i ODBC datasource (using Oracle ODBC drivers). After linking the tables in Access, I inspect the data contained in the linked tables. For...
2
by: NasirMunir | last post by:
I have created a table in access (copied from excel). Then I created a form which contains a text field and a list box. The text field is actually a look-up field, where a user can enter a searchable...
11
by: dba | last post by:
Have been displaying data from database using html for some time but just recently trying to display data back to "form". Can't find answer. <form method="post" action="<?php echo $PHP_SELF;?>">...
3
by: Nightcrawler | last post by:
I have a website that does the following: 1. it accepts a keyword through a textbox in the UI 2. once the submit button is clicked it goes out and spiders a few websites using the keyword...
3
by: ejamnadas | last post by:
I have a form which combo boxes (say cmb1 and cmb2). The form also has a subform with a listbox whose rowsource is a query based on the values selected in the comboboxes. In the After Update event...
0
by: Del | last post by:
Hello and thanks for any and all assistance! I have a database that is used by several users on several different machines. The backend database is housed on a file server. Each user has a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.