473,385 Members | 1,474 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.

Limiting Row Source Property of Multiple Combo Boxes

doma23
107 100+
I have 5 combo boxes which represent certain periods.
The row source of these 5 combo boxes is table tblRefDate.
What I want to do is to make a procedure that when period is inserted in any of these combos will limit periods
shown in other combo boxes, ie. it will exclude the period or periods which are already shown
in one or more of other combos.

I was thinking about making 5 functions and puting them respectively in ROW SOURCE property of the periods.
I was imagining that function should look something like this code under, but I'm still struggling a lot with writing
the string correctly.

Period1 - Row Source: fRow_Period1
Expand|Select|Wrap|Line Numbers
  1. Public Function fRow_Period1()
  2. Dim sRow1 as String
  3.  
  4. sRow1 = "SELECT tblRefDate.RefDate from tblRefDate WHERE [RefDate] <>" _
  5.         & me.cboPeriod1 & "WHERE [RefDate] <>" & me.cboPeriod2 & WHERE [RefDate] <>" & me.cboPeriod3
  6.  
  7. fRow_Period1 = sRow1
  8. End Function
Tnx.
Jul 26 '10 #1

✓ answered by NeoPa

You don't say, but I'm guessing maybe the [RefDate] field is of type DateTime. That makes the SQL a little more tricky, but Pat's solution is very much on the right lines nevertheless.

We're working on very little information here. Please provide details of what you've tried and what the error message was for each attempt. Telling us that you had various errors in your attempts, but no further details is very frustrating and makes helping you very difficult.

The RowSource of each of your ComboBoxes should be similar to this one for the first (cboPeriod1) :
Expand|Select|Wrap|Line Numbers
  1. SELECT [RefDate]
  2. FROM   [tblRefDate]
  3. WHERE  [RafDate] Not In(CDate([Forms]![FormName].[cboPeriod2]),
  4.                         CDate([Forms]![FormName].[cboPeriod3]),
  5.                         CDate([Forms]![FormName].[cboPeriod4]),
  6.                         CDate([Forms]![FormName].[cboPeriod5]))
Each ComboBox should have an AfterUpdate event procedure that calls a .ReQuery() of all the other ComboBoxes.

8 2036
patjones
931 Expert 512MB
To comment specifically on your SQL, and not to suggest one way or the other whether this is the best way to do it, you would need only one WHERE:

Expand|Select|Wrap|Line Numbers
  1. sRow1 = "SELECT tblRefDate.RefDate 
  2.          FROM tblRefDate 
  3.          WHERE [RefDate] <> " & Me.cboPeriod1 & " AND [RefDate] <> " & Me.cboPeriod2 & " AND [RefDate] <> " & Me.cboPeriod3

There is a shorthand way of doing this as well:

Expand|Select|Wrap|Line Numbers
  1. sRow1 = "SELECT tblRefDate.RefDate 
  2.          FROM tblRefDate 
  3.          WHERE [RefDate] NOT IN (" & Me.cboPeriod1 & ", " & Me.cboPeriod2 & ", " & Me.cboPeriod3 & ")"

Let us know if it works.

Pat
Jul 26 '10 #2
doma23
107 100+
It doesn't work.
I've been playing with it but I keep getting strange messages, ie. the function doesn't exist, can't find this and similar.
But if you know more efficient way to do this, please share. This with functions was just an idea which might miss some logical steps...
Jul 26 '10 #3
NeoPa
32,556 Expert Mod 16PB
You don't say, but I'm guessing maybe the [RefDate] field is of type DateTime. That makes the SQL a little more tricky, but Pat's solution is very much on the right lines nevertheless.

We're working on very little information here. Please provide details of what you've tried and what the error message was for each attempt. Telling us that you had various errors in your attempts, but no further details is very frustrating and makes helping you very difficult.

The RowSource of each of your ComboBoxes should be similar to this one for the first (cboPeriod1) :
Expand|Select|Wrap|Line Numbers
  1. SELECT [RefDate]
  2. FROM   [tblRefDate]
  3. WHERE  [RafDate] Not In(CDate([Forms]![FormName].[cboPeriod2]),
  4.                         CDate([Forms]![FormName].[cboPeriod3]),
  5.                         CDate([Forms]![FormName].[cboPeriod4]),
  6.                         CDate([Forms]![FormName].[cboPeriod5]))
Each ComboBox should have an AfterUpdate event procedure that calls a .ReQuery() of all the other ComboBoxes.
Jul 26 '10 #4
patjones
931 Expert 512MB
I echo NeoPa's request that you tell us exactly what the error message says. We'll probably be able to pinpoint the matter very quickly then. Thanks.

Pat
Jul 26 '10 #5
doma23
107 100+
Thank you both guys very much.
And sorry for not providing all the informations. My system on job is in Italian and it takes me a lot of time to decipher everything.
I've expected that somebody will point me other way, as I felt that my idea is not the most efficient one. I've post it just to not give false impressions that I haven't tried anything.
Also these SQL strings in VBA make me want to pull my hair off (which I don't have a lot btw). :)
Over the weekend I was struggling for almost 2 hours to get this line of code correctly:
Checks if data exist in the table based on the value of 3 textboxes from the form
Expand|Select|Wrap|Line Numbers
  1. If DCount("*", "[DATA_T]", _
  2.     "(([bank]='" & Form_frmMain.cmbBank & "') AND (" & "[division]='" & Form_frmMain.cmbDivision & "') AND (" & "[ref_date]='" & Converted_Period1 & "'))") > 0 Then
  3.     DataExist1_Period1 = True
  4. End If
Anyway, I finished the tool yesterday and it has all the functionalities it needs to have.
But I wanted to add one more thing - this limitation on combo boxes, and when I started dealing again with SQL strings and error messages on Italian started to pop out, one after another - my head was about to explode.
----------
Anyway, NeoPA your solution worked. It was exactly what I wanted.
The thing is that I wasn't sure if it's possible to refer to the controls directly with the SQL. Somebody told me it needs to be done via functions. Blah...

So, just to repeat, here is the solution.
Periods are saved as text, not as date.

To be put directly into the "Row Source" for each cmbPeriod combobox. Combobox for which you're setting the Row Source should not be included.
cmbPeriod1 - Row Source property
Expand|Select|Wrap|Line Numbers
  1. SELECT [Ref_Date] FROM [tblRefDate] 
  2. WHERE  [Ref_Date] Not In
  3. ([Forms]![frmMain].[cmbPeriod2],
  4. [Forms]![frmMain].[cmbPeriod3],
  5. [Forms]![frmMain].[cmbPeriod4],
  6. [Forms]![frmMain].[cmbPeriod5])

Also, like NeoPA said, Requery on After Update procedure:
Expand|Select|Wrap|Line Numbers
  1. Public Sub cmbPeriod1_AfterUpdate()
  2. Me.cmbPeriod2.Requery
  3. Me.cmbPeriod3.Requery
  4. Me.cmbPeriod4.Requery
  5. Me.cmbPeriod5.Requery
  6. End Sub
Jul 26 '10 #6
NeoPa
32,556 Expert Mod 16PB
Doma,

Thank you for this amusing post. I can just imagine your frustration trying to deal with SQL strings within VBA. It's a common problem even experienced programmers struggle with.

Also for posting your solution. It clearly explains that you have fully grasped the concepts needed, which is always good for us to see.

Here's to your remaining hair. May it stay with you always :)
Jul 26 '10 #7
doma23
107 100+
@NeoPa
Hahaha, thank you my friend.
This is the first and only Access forum I'm using.
So far, my problems always found their solutions here, thanks to all of you kind people.
NeoPA, once I'm in London I'm buying a beer!
Cheers!
Jul 27 '10 #8
NeoPa
32,556 Expert Mod 16PB
Let me know when. It's quite hard to find me in London unless you know where to look :D
Jul 27 '10 #9

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

Similar topics

1
by: Young J. Putt | last post by:
I have what I thought was a relatively simple data situation that I can't seem to get working using ADO.NET datasets and data binding. I have an "Issues" table which records the UserID of the user...
2
by: Damon Cherne | last post by:
Here is my issue. I have created a form called “Search” that has several unbound combo boxes, one for each of the attribute that match a column in the Table . Each combo box has input from a...
2
by: visionstate | last post by:
Hi there, I am working on a form that uses 3 text boxes and 3 combo boxes. When any data is entered into any of these, I click a command button and this requeries a sub query in the form and...
2
by: Pablo | last post by:
I have a Continuous Form based on the following table: sku, description, categoryId, subCategoryId I restrict the initial dataset to include one value for categoryId, but it may include...
1
by: Shawn Yates | last post by:
It has been a while since I have done anything on MS Access and I seem to be a bit rusty. I hope someone could help me solve my issue. I have a form that has multiple combo boxes on it. Each box...
4
by: Chansen | last post by:
I have a form with mulitple combo boxes that populates criteria in a query. I want to add a button to clear the selections in all of the combo boxes. What code do I use? Thanks!
9
WyvsEyeView
by: WyvsEyeView | last post by:
I have a form that has four unbound combo boxes: cboType, cboVersion, cboStatus, cboReview. I want to write a query that basically lets users make selections in as many combo boxes as apply...only...
12
by: micarl | last post by:
How would i print a report based on criteria selected from several Combo Boxes as well as multiple Multi Select List Boxes, that are located on the same form? I can get one Multi List Box, just...
2
by: genkidave | last post by:
Hi there, I have three combo boxes that I would like to have Disabled (grayed out???) and preselected to a particular selection until a radio button (YES) is clicked, thus enabling the combo...
6
by: slenish | last post by:
Hi all, I have asked this question a couple of times but I keep getting no answer so I thought I would give it one more go. I have 3 combo boxes on a form. Each of these combo boxes pulls...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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...

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.