473,385 Members | 1,753 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,385 software developers and data experts.

How to change combobox query on click?

70 64KB
I have a combo box on a form (which is bound to tblEquipment table). The combobox is bound to tblIPAddressFK which is a number field linking to the primary key in tblIPAddress. The RowSource for this combo box is a simple query containing two fields, the PK and the IP Address (text). The purpose of this is to display the text IP address field, while being able to modify the FK in tblEquipment.

The problem I have is I need to view current records, as well as edit records using the same controls. For all the other combo boxes, this approach has worked well for me. I use the same controls to view records as I do to edit them. Additionally, I can change the form to data entry mode and use the same controls to add a new record. The if statement is kinda long, but it works.

The problem with this here is that whenever I need to add a new record or edit an existing record, I need to click on the combo box and see IP addresses that are not already in use. I can do this by changing the query to include a LEFT OUTER join to tblEquipment, adding tblIPAddressFK WHERE IS NULL and then the combo box will only display IP addresses that are not already in use.

However, if I use this query and am viewing a record in tblEquipment which already has an IP address in the tblIPAddressesFK field, the combo box will not display anything in them.

So, basically. I think I need to have two RowSource queries... one to view data, and another one for whenever the combobox is clicked. Is this possible?

An alternative, I think, would be to create the query that filters out IP addresses already assigned to equipment. But then, add one value to the combo box for the ip address assigned to the equipment which is being viewed on the form.
Apr 6 '16 #1
2 1927
NeoPa
32,556 Expert Mod 16PB
This really depends on exactly what you want to do.

If new records only need to be assigned new and unused values, but existing records can never be changed, then you can set the .ControlSource of the ComboBox in the Form_Current() event procedure. You could use the .NewRecord value to determine which to use for that record, but remember that, once saved, that same current record changes what it needs.

If you need existing records to be able to show their current values, but also be able to change them to new and previously unused values, then you set it up in the design and use your second idea.

PS. If your third paragraph is an accurate reflection of your requirements then your later idea will be required.
Apr 6 '16 #2
jforbes
1,107 Expert 1GB
I think there was another question a couple months ago that was very similar to this, but I couldn't seem to find it, so...

I think you can do what you want in the Where Clause of the RowSource for the ComboBox. You can include the restriction of unused IP Addresses along with including the IP Address currently stored on the Record.

This is an example that uses a Project/Employee scenario. Only Employees that are enabled are available in the DropDownList, but the currently selected Employee is also included regardless whether or not they are Enabled:
Expand|Select|Wrap|Line Numbers
  1. SELECT Employee.EmployeeID, Employee.Name, Employee.Enabled 
  2. FROM Employee 
  3. WHERE [Employee].[Enabled] <> 0 
  4. Or [Employee].[EmployeeID]=[Forms]![EmployeeProject]![EmployeeID]
The Form will also need the following code so that the DropDownList is refreshed to include the current EmployeeID whenever the Current Record changes:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.     Me.cboEmployeeID.Requery
  3. End Sub
In the above, the Employee of the Current Record will always be included in the ComboBox DropDownList, so it will always display correctly.
Apr 6 '16 #3

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

Similar topics

4
by: perspolis | last post by:
hi I manage a double click event in a combo box.. but this event doesn't fire ???? I don't know why??
1
by: MadCrazyNewbie | last post by:
Hey Group, How could I do it so if something isn`t listed in my ComboBox (It looks up a Database Coloumn), When a User Double Clicks on the ComboBox it brings up a form so they Can add it in...
2
by: Kim C | last post by:
Can I add an option to the menu that is displayed for a right-click on a ComboBox?
0
by: zhuang | last post by:
Hi, Adding combobox to datagrid has been posted many times. I have a datagrid which has multiple combobox columns and normal textbox columns. But how could I change other combo box values at...
6
by: JonnyRotten | last post by:
I have two tables The first has a ID (key) field and enteries for Name The second has a ID field (tied to the first) and then 6 fields for activities. Called Activity1, Activity2, etc etc I...
0
by: =?Utf-8?B?Q2VWYXU=?= | last post by:
Hi there, I'm trying to use a ComboBox in a way, that the Control is disabled (Enable = false), but I still want to use the Controls Click Event. Does anybody know a way ? Regards,
1
by: cwoll | last post by:
I have a table with 5 different fields. ID Field Name = This field refers to land not a field in access. 2007 Crop 2008 Crop 2009 Crop I now have a query that just gives me "Field Name" and...
18
by: wizdom | last post by:
Help - change text on click - text has another onclick inside with php variables ---------- I think what I'm trying to do is simple. I have a 2 buttons on a page. 1 button allows a thread of...
1
by: Rickard Hill | last post by:
Fellow csharpers.. I got a problem that I haven't found a solution for, and are hoping to get some help. I have the following piece of code (with commented out parts that I tried without...
6
mjoachim
by: mjoachim | last post by:
I currently have a Combobox that is linked to a table and is designed to limit possible entries based on 2 other form fields. To do this, I am using this query: SELECT .CostCode FROM WHERE...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...

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.