473,761 Members | 8,813 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Update a select query code by selecting an item in a combo box ?

44 New Member
Hi,
I've got the follwing issue.
I have a command button on a form, which selects a query after beeing pressed. The data from the query is a combination of data from 3 tables.
Now I want to make a step in between. I want to give the users the possibility to restrict the output of the query.
E.g. The query previously showed all staff. Now the user selects only one department (maybe a combo box having an event procedure...) and when they press the button the query shows only the staff from that department.
I understand that that means I want to enter a criteria in the query with the help of the form.
The department actually is already part of the output from the query.
I really don't know if this is possible and how to do it?
Anybody out there with an idea? :)
Cheers
Sep 28 '06 #1
3 3236
PEB
1,418 Recognized Expert Top Contributor
Hi,

It's possible - simply you have to delete your old query and recreate it with the respective criteria!

How to do it....

The query creation can be done using this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Set mydb = CurrentDb()
  3. Set Myquery = mydb.CreateQueryDef(names, SQLS)
  4.  
  5.  
And the query del...

Expand|Select|Wrap|Line Numbers
  1. Set mydb = CurrentDb()
  2. mydb.QueryDefs.Delete names
  3.  
  4.  
And I don't mention something between the 2 operations...

The SQL that U have to Save to your query! It's up to You to invent it! ;)

But not hesitate to ask if pb! :)

Best regards

:)
Sep 30 '06 #2
isetea
44 New Member
I'm not sure, if I understood your correct. I should create a query with a criteria and than delete it again. So always if somebody selects a department from the combo box this will be the new criteria in the code / query ? But how can I connect a combo box (where somebody selects any of 12 values) and a command button (or something else), which runs the code and selects all the records from the tables where the criteria fits?

I mean, I have a combo box, which shows all the departments in the list and where somebody can select the dept which is wanted. And I have a command button which opens an existing query.
Now I need to combine both to run the query with the selected dept as the criteria.

Or I'm totally wrong and there is an easier way to get it. But I'm still very lost...

Hi,

It's possible - simply you have to delete your old query and recreate it with the respective criteria!

How to do it....

The query creation can be done using this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Set mydb = CurrentDb()
  3. Set Myquery = mydb.CreateQueryDef(names, SQLS)
  4.  
  5.  
And the query del...

Expand|Select|Wrap|Line Numbers
  1. Set mydb = CurrentDb()
  2. mydb.QueryDefs.Delete names
  3.  
  4.  
And I don't mention something between the 2 operations...

The SQL that U have to Save to your query! It's up to You to invent it! ;)

But not hesitate to ask if pb! :)

Best regards

:)
Oct 3 '06 #3
PEB
1,418 Recognized Expert Top Contributor
Hi icetea,

Imagine that you have the SQL of your query with the 3 tables without conditions..

Now try to vizualize 1 departement by manually typing the respective departement!

Pass in SQL Query view and Copy this SQL!

So in your combobox you need to create an After Update Event procedure...


In this procedure needed to type

Me.recordsource ="PASTE YOUR SQL WHERE [Departement]='"+Me!Combobox 1+"''"

You need to replace in the expression... And you will have the needed result!

Best regards
Oct 7 '06 #4

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

Similar topics

3
4934
by: Kevin Pedersen | last post by:
Hello, I am using an editable datagrid. After I save the changes the datagrid shows the old values. I've read the posts about the Page_Load and not binding the datagrid each time. The SQL that is being sent to the database is correct and the changes are eventually being made. If I refresh the page after the update then the new values appear. I noticed that when I put a breakpoint in my update handler everything works fine. When I take...
5
3728
by: keri | last post by:
Hi, I am struggling to learn access and VBA whilst creating a db, progress is slow! So far I have managed to run cascading combo boxes on a form by using a sub in the after update procedure of the 1st combo box to populate the second, using code like below. Select Case combo1.value Case "1"
5
2597
by: njb35 | last post by:
Hi all I'm beginning my foray from VBA into VB 2005 Express, and enjoying some of the efficiencies it provides! I'm stuck with some dataset handling however that I _think_ can be automated but I can probably code what I want to do the hard way. I've searching around online but can't find an answer to this specific question. Here's the situation: I have a dataset table with 3 fields: one indexed as a primary key and the other two...
1
4756
by: bjgdal | last post by:
I am currently trying to create an application which will help me in my work. To do this I need to update a field called "Installations" in a table with the same value for all records. The value however is from a list of about 1300 military installations so typing in the value in an update query is not optimum. I am able to get a combo box in a form to bring up the list and to get a parameter query to come up (after selecting the...
4
3032
by: Swinky | last post by:
I am trying to make a combo box dependent on a text box. I cannot get the combo box to pull the related data from the text box. I have been all over this user group & have tried several versions of code to no avail. I would like to display all contact names (in the combo box) related to the customer number in the text box. Here's what I have:
7
10356
by: Rotsey | last post by:
Hi, I am having a problem trying to select an item with the enter key. I want to work the combo with the keyboard. So when I use the down arrow to browse the list I want to then hit the enter key as if selecting an item with the mouse. How do I do this?
0
2304
by: XenReborn | last post by:
Ok this should be simple. I made a form, added a combobox (for selecting items to edit, not for updating fields), several textboxes, a few checkboxes etc. On formshow it connects to my database, draws down the existing data, no problem. All the records in the datatable that were the result of a query, I could select from, and the other databound components would display the records contents, no problem..... however.... when i add a new row, the...
2
2636
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to update the information which is stored in a SQL database. In testing we noticed that the form was updating correctly but the update mechanism was also updating the first record of the table in the sql database every time. No error messages are on...
2
3413
by: gagandeepsngh | last post by:
'Code for selecting a particular data from database '***** START ***** sSQL = "SELECT name FROM trans" cmd = New OleDbCommand(sSQL, con) Dim reader As OleDbDataReader = cmd.ExecuteReader() While reader.Read() Dim tempitem As String tempitem = reader.GetString(0)
0
9376
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9988
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9923
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9811
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8813
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3911
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.