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

combobox filled based on another field

64 64KB
Hi,"

I have a form called "frm_detail"
On the form i have two combobaxes called

cbo_soort
cbo_fase

cbo_soort has de items (i use dots to seperate the items, cannot put a table in place)

ID_soort.....Soort_traject
1.................nieuw
2.................verlenging
3.................uitbreiding
4.................anders

cbo_fase is based on a Query called "Q_fase" which has the items;

ID_fase.....Fase.......Soort_traject
1................fase 1.....N
2................fase 1a....V
3................fase 1b....B
4................fase 2.....B
5................fase 3.....B

Question: I would like to be able to do the following;

If cbo_soort = "2" then i would like the list in cbo_fase to only show the items where Soort_traject is V or B (so N should be discarded)

If cbo_soort = <> "2" then i would like the list in cbo_fase to only show the items where Soort_traject is "N" or "B"

I am trying to find a solution for the "criteria" part in the Q_fase qury on the field "Soort_traject" but i can't figure out how to do this...

Any help would really be appreciated.
Thanks,
Pierkes
Jul 11 '14 #1

✓ answered by twinnyfo

Expand|Select|Wrap|Line Numbers
  1. Private Sub cbo_soort_AfterUpdate()
  2.     Dim strQL As String
  3.     strSQL = "SELECT * FROM Q_fase "
  4.     If Me.cbo_soort = 2 Then
  5.         strSQL = strSQL & _
  6.             "WHERE Soort_traject = 'V' " & _
  7.             "OR Soort_traject = 'B';"
  8.     Else
  9.         strSQL = strSQL & _
  10.             "WHERE Soort_traject = 'N' " & _
  11.             "OR Soort_traject = 'B';"
  12.     End If
  13.     Me.cbo_fase.RowSource = strSQL
  14.     Me.cbo_fase.Requery
  15. End Sub
You may encounter problems when cbo_soort equals 3 or 4 (what do you want it to do in those situations?

11 1154
jimatqsi
1,271 Expert 1GB
In the After_UPdate event of cbo_soort you want to change the rowsource property of the other combo box. You can fill the rowsource with a query string if the combo box rowsourcetype property is "table/query".

Are you able to use VBA to form the necessary query string?

Jim
Jul 11 '14 #2
Pierkes
64 64KB
Hi Jim,

Yes, if nessesary i can use VBA, however, what the string should be...??? i do'nt know, can you help ?

thanks,
Pierkes
Jul 11 '14 #3
twinnyfo
3,653 Expert Mod 2GB
Expand|Select|Wrap|Line Numbers
  1. Private Sub cbo_soort_AfterUpdate()
  2.     Dim strQL As String
  3.     strSQL = "SELECT * FROM Q_fase "
  4.     If Me.cbo_soort = 2 Then
  5.         strSQL = strSQL & _
  6.             "WHERE Soort_traject = 'V' " & _
  7.             "OR Soort_traject = 'B';"
  8.     Else
  9.         strSQL = strSQL & _
  10.             "WHERE Soort_traject = 'N' " & _
  11.             "OR Soort_traject = 'B';"
  12.     End If
  13.     Me.cbo_fase.RowSource = strSQL
  14.     Me.cbo_fase.Requery
  15. End Sub
You may encounter problems when cbo_soort equals 3 or 4 (what do you want it to do in those situations?
Jul 11 '14 #4
Pierkes
64 64KB
Hi twinnyfo,

In case 3 or 4 i want the same as in case 1. The only thing that is differten is case 2.

Regards and thank you very much for your help !,
Pierkes
Jul 11 '14 #5
twinnyfo
3,653 Expert Mod 2GB
Then the code provided should either work or get you very close to your solution... Hope it helps!
Jul 11 '14 #6
Pierkes
64 64KB
Hi twinnyfo,

Your code works perfectly.
I have only one problem...

When the form now loads, it does not show anything in the cbo_fase field which is not correct because usually there is something in that field in the database. The field in the database is called [tr_fase] which is also the controlsource for cbo_fase.

How can i make it so when the form opens it shows the entry in the [tr_fase] field in the cdb_fase and when i change the value of [Soort traject] the dropdown box gives the wright listing ?

Thanks for your help !
Jul 14 '14 #7
twinnyfo
3,653 Expert Mod 2GB
Pierkes,

The combo box should have a row source that you have already established for it. The only thing my code should have changed is how the combo box looks up rows after cbo_soort is updated. Does this make sense?
Jul 14 '14 #8
Pierkes
64 64KB
Hi,

No, this does not make sense...the entry is in the field, but i do not see it because the form waits until i come to the afterupdate of the [Soort traject] part.

then the field entry is visible again in the [tr_fase] combobox.

How to move on from here, i do not know...
Any ideas ?

Regards,
Pierkes
Jul 14 '14 #9
twinnyfo
3,653 Expert Mod 2GB
When you open your form in deesign view and click on cbo_fase. In its properties, what is its row source? At a minimum, it should be:

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM Q_fase;

You may also run into additional problems with this type of set up with multiple records, because once you select a value for cbo_soort and move to a different record, if that record does not have the same value for cbo_soort, the value for cbo_fase will not show up.

One work-around is to have the code in post #4 in the OnCurrent event for the Form (or as a separate procedure called from the Form's OnCurrent event and the cbo_soort AfterUpdate event.

It can take some playing around, but it is not too difficult. You have to remember that combo boxes, when bound are looking for the row in its row source that meets the value of its control course. If it isn't there, it is blank.

Hope this hepps.
Jul 14 '14 #10
Pierkes
64 64KB
Hi twinnyfo,

That was indeed the problem !
Thanks you very much for your help !

I put in;

SELECT Q_Fase.ID_Fase_N, Q_Fase.Verkoop_Fase_N FROM Q_Fase;

And it workt perfectly.

Best regards,
Pierkes
Jul 15 '14 #11
twinnyfo
3,653 Expert Mod 2GB
Glad this could help! Hope to see you here again!
Jul 15 '14 #12

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

Similar topics

6
by: jochen scheire | last post by:
Is there a way I can calculate a field in a form based on another field in the same form. When clicking submit, both values should be posted to the next page. I want to be able to type in a value...
7
by: NotGiven | last post by:
I'd like to have several levels of field selection. For example, field one has three choices. Once you choose on form field one, several selections show in field based that ARE BASED ON your...
6
by: Greg | last post by:
I am trying to change the value of one field in my query based on the value in another. If Field 1 had the text "ONACCNT" then in Feild 2 I want the date to change to today's date. Any help would...
0
by: Ray Holtz | last post by:
Is it possible to autofill a field based on what is entered into another field in a form? My form has an employee field, and department field. In an Items Table, I have fields FldEmployee, and...
3
by: skinnybloke | last post by:
Hi - I have the following VB function within MS Access which is called via a query. How do I modify this code so that it will only do the replacement based upon the value of another field on the...
3
by: martin DH | last post by:
Hello, In a report, for every record, I would like a checkbox to appear checked if a certain field contains any value. The field is Client_comments. (memo field) I added a checkbox called...
5
by: lsimonelli via AccessMonster.com | last post by:
On a form, how do I require entry of a field based on the data in another field? I do not want to require at the table level. I have a field that the user selects where a refund goes. If they...
7
by: simulationguy | last post by:
This is causing my some grief :) I have a form that displays records in a tabular format, one field is a combo box that displays values from another table. But I only want some of those values...
4
by: nedryerson | last post by:
Hi, I'm trying to get a certain field to appear only when a value from another combobox field is selected. Specifically, when "Sample Rejected" is selected in the field "PcrLabResults," I would...
5
by: jmtrobough | last post by:
Situation is: I have a report that has a field that will be formatted based upon the results in another field. For example if 'Field 2' equals "IBR" 'Field 1' would be formatted with – italics,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: 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: 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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.