473,394 Members | 2,090 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,394 software developers and data experts.

Displaying Value in Unbound Control

124 100+
So you have some background to what I'm doing, I'm building a degree audit for my school which requires the building of degree requirements by matriculation year/term (stored in DegReq) and assigning them to students (StdDegReq). This is a little long but I wanted to provide as much information that I thought necessary.

There are 3 tables related to my problem:

MatricYT: MatricId (PK), MatricYear, MatricTerm
DegReq: DegReqId (PK), MatricId (FK) (degreqs are built by matric year/term)
StdDegReq: StdDegReqId (PK), PersonId (FK), DegReqID (FK)

I have a form whose record source is StdDegReq which allows a user to assign a degree requirement plan to a student. The form has two combo boxes: cboMatricId (unbound) and cboDegReqId (bound to DegReqId).

cboMatricId's rowsource pulls all available values in MatricYT and cboDegReqId's rowsource pulls all available values in DegReq. Because I want the values in cboDegReqId to be determined by the MatricId selected in cboMatricId I've put the following code in cboDegReqId's GotFocus event:
Expand|Select|Wrap|Line Numbers
  1. Me.cboDegReqId.RowSource = "SELECT DegReq.DegReqId, CodeProgram.Program & "" / "" & CodeDegree.Degree & "" / "" & CodeCurriculum.Curriculum AS PDC " _
  2.                         & "FROM ((DegReq INNER JOIN CodeProgram ON DegReq.ProgramId = CodeProgram.ProgramId) INNER JOIN CodeDegree ON DegReq.DegreeId = CodeDegree.DegreeId) " _
  3.                         & "INNER JOIN CodeCurriculum ON DegReq.CurriculumId = CodeCurriculum.CurriculumId WHERE DegReq.MatricId = " & Me.cboMatricId
After I select a MatricId and then a DegReqId, close the form and open it up again, cboDegReqId displays the deg req plan I assigned to the student but the cboMatricId combobox remains blank because it can't find the MatricId associated with the DegReqId. My question is, how do I get the combobox to display the matric Year/Term of the MatricId of that DegReqId? The easiest way would be to store MatricId in StdDegReq also and bind the control to that field, but that would violate normalization rules since MatricId is already stored in DegReq. I've been trying to figure this out but it has me stumped. Your help is much appreciated. Thanks!
Apr 21 '10 #1

✓ answered by NeoPa

Sorry. I was confusing your intelligent approach with more specific Access experience. I skipped some important information. Let me point you a little more clearly.

First start by identifying the control on your form that it will be filtered on. In the code you specify [txtDegReqId], yet earlier you referred to a ComboBox named [cboDegReqId]. Whichever is the one you need, you should create an AfterUpdate procedure (Select control; Click in the After Update property of the Properties Pane; Select the value "[Event Procedure]"; Enter the code).

The code should be something like :
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboDegReqID_AfterUpdate()
  2.     cboMatricID = DLookup(Expr:="MatricId",
  3.                           Domain:="DegReq",
  4.                           Criteria:="[DegReqId]=" & Me.[cboDegReqId] & ")
  5. End Sub

18 3290
NeoPa
32,556 Expert Mod 16PB
I can tell from how your question is formulated that I'm dealing with an intelligent, competent person, so I'll start with this link Example Filtering on a Form).

If this doesn't help you to your solution, or if you find it misses the point, post back and we can progress in more detail.
Apr 22 '10 #2
bullfrog83
124 100+
I downloaded the sample db and reviewed it but found that it doesn't help me (unless there's something that I missed).

Taking what I wrote above, here's perhaps a simpler way of explaining what I want to do:

This is the rowsource of my bound combobox cboDegReqId:
Expand|Select|Wrap|Line Numbers
  1. SELECT DegReq.DegReqId, DegReq.MatricId, CodeProgram.Program & "/" & CodeDegree.Degree & "/" & CodeCurriculum.Curriculum AS PDC
  2. FROM ((DegReq INNER JOIN CodeProgram ON DegReq.ProgramId = CodeProgram.ProgramId) INNER JOIN CodeDegree ON DegReq.DegreeId = CodeDegree.DegreeId) INNER JOIN CodeCurriculum ON DegReq.CurriculumId = CodeCurriculum.CurriculumId;
The first two columns I have hidden by setting their width to 0. How do I get the MatricId of the selected DegReqId in the bound combobox to display in the unbound combobox cboMatricId? I can set the control source of cboMatricId to:
Expand|Select|Wrap|Line Numbers
  1. =DLookUp("MatricId","DegReq","DegReqId = [txtDegReqId]")
This works for the row that has a DegReqId, but on the next row I'm unable to select a value in cboMatricId which poses a problem if I have to assign another DegReqId to the student because he's double majoring for instance. I know that's probably because of the DLookup function and also because on the new record row there's no DegReqId because one wasn't selected yet in cboDegReqId and you can't select a value in cboDegReqId until you select a value in cboMatricId since the values in cboDegReqId are dependent upon what's selected in cboMatricId. So I'm stuck in a catch-22!
Apr 22 '10 #3
bullfrog83
124 100+
NeoPa
Since I see you are an administrator what is the difference between "Post Reply" above the Quick Reply and the "reply" which takes you to the QUick Reply at the bottom of every post? I'm new here and am not sure when to use which one.
Apr 22 '10 #4
NeoPa
32,556 Expert Mod 16PB
First let me say that this whole area is in a state of flux at the moment, so the details are not guaranteed except at time of my posting this :
  • The Post Reply button takes you straight to the Advanced Reply page with no automatic quoting. The Advanced Reply page has more features available than the Quick Reply.
  • The Quick Reply box doesn't involve navigating away from the page first. Submitting the reply from here can be done either directly (Post Quick Reply), or via the Advanced Reply page (Go Advanced). The latter will take anything already prepared and preview it ready for continuing in the advanced mode.
  • The Reply button associated with each post will take you straight to the Quick Reply box, but will set a flag to add a quote of the associated post to your reply. You will see this if you subsequently select Go Advanced.
Apr 23 '10 #5
bullfrog83
124 100+
@NeoPa
Thanks for the clarification! However, do you have any ideas concerning my issue? I followed your link and downloaded the sample db but it didn't help me. My follow-up is post #3 in this thread where I hope I provided some more useful information. Thanks!
Apr 26 '10 #6
NeoPa
32,556 Expert Mod 16PB
Sorry for the delay in responding. There is a lot to look through in here so I had to postpone looking at it until I had a bit of time within which to think it through. Unfortunately, I find myself a little stuck. Looking at your bound ComboBox - cboDegReqID - I can follow the reference to [DegReq], as that is explained in the OP (post #1). I get a bit lost when trying to make sense of the rest of it though.

As for cboMatricID, I cannot truly say what this should be, but I'm pretty sure a DLookup() call is not required. A possible alternative, without properly understanding your situation (worth testing out though), might be :
Expand|Select|Wrap|Line Numbers
  1. SELECT [MatricID]
  2. FROM   [DegReq]
  3. WHERE  [DegReqID]=Forms!{FormName}.txtDegReqID
Clearly, you'd need to substitute {FormName} with the actual name of the form.
Apr 26 '10 #7
bullfrog83
124 100+
@NeoPa
No need to apologize! I'm grateful for whatever assistance I receive. I just wasn't sure if you saw it or not so I wanted to make sure and certainly didn't mean to come off as "pushy".

I may be having a brain lapse here but where do you want me to insert the SELECT statement that you provided? I already have the row source of the cboMatricId as follows:
Expand|Select|Wrap|Line Numbers
  1. SELECT MatricId, MatricYear & "/" & MatricTerm AS MatricYT
  2. FROM MatricYT
  3. ORDER BY MatricYear & "/" & MatricTerm DESC;
I certainly understand what you're saying about it being difficult to understand this without actually seeing it. I can easily have an unbound textbox that pulls the year/term of the MatricId for the selected value in cboDegReqId. But that seems superfluous, especially since there'll be a blank combobox for each record. If I find no solution I suppose I'll have to add MatricId to StdDegReq and bind cboMatricId to it. I'd hate to do it but what other choice would I have?
Apr 26 '10 #8
NeoPa
32,556 Expert Mod 16PB
My suggestion was in response to your DLookup() code included in post #3. I was under the impression that you wanted it filtered to list only those items related to the DegReqID control on your form. Have you tried the suggestion? Does it find the right values? We can sort out tidying it up to provide fuller info later if we're on the right lines.
Apr 27 '10 #9
bullfrog83
124 100+
@NeoPa
You understood correctly. My question was do you want me to insert the code you provided as the rowsource? If so, then that wouldn't work because for a new record, you select the MatricId first in the unbound combobox and then the DegReqId in the bound combobox. The rowsource of cboMatricId would find no values since a DegReqId isn't selected yet.

I could have created one big combobox that concatenates the values of MatricId & DegReqId which would solve my problem. However, it would result in hundreds of values to scroll through since you can have dozens of DegReqIds tied to one MatricId. Therefore, I thought it best to break it up into two comboboxes for easier selection: the first is unbound that allows you to select the MatricId, and the second is bound that allows you to select a DegReqId that's tied to the selected MatricId. Getting the MatricId of the selected DegReqId to display in the unbound is my problem.
Apr 27 '10 #10
NeoPa
32,556 Expert Mod 16PB
In that case try :
Expand|Select|Wrap|Line Numbers
  1. SELECT [MatricID]
  2. FROM   [DegReq]
  3. WHERE  Nz(Forms!{FormName}.cboDegReqID,'') In([DegReqID],'')
** Edit **
The text is for the Record Source, as you say.
Actually, I suspect changing this would be unnecessary. Simply call a .Requery() whenever the cboDegReqID changes (AfterUpdate) to update the list to match.
Apr 27 '10 #11
bullfrog83
124 100+
@NeoPa
As I reread our posts I think we're not on the same page. My problem does not concern the rowsource of cboMatricId. I can get that to work fine. Let me explain it this way:

1) I open the bound form
2) I select a MatricId from the unbound combobox cboMatricId which then determines the available values in my bound combobox cboDegReqId
3) I select a DegReqId
4) Record saves
5) I close the form
6) I reopen the form and the DegReqId I selected displays in cboDegReqId but no value displays in the unbound cboMatricId because it's not bound to any field. I can get the right value to display if I use a DLookup (Post #3) but then if I decide to add another DegReqId to the person, I'm unable to select a value in cboMatricId for the new record. Maybe there's no way to do what I want to do?
Apr 27 '10 #12
NeoPa
32,556 Expert Mod 16PB
I suppose I'm confused by your requirement. You have a bound ComboBox (cboDegReqID) and an unbound one (MatricID). From this I understand that you want the value of cboDegReqID to be saved with the form's record, but you don't want the value of cboMatricID to be.

From what you're describing though, it seems that you're surprised that this value is not saved - is not available next time you navigate to that record. Am I missing something here?
Apr 27 '10 #13
bullfrog83
124 100+
@NeoPa
No, you got it. However, I'm not surprised that the value isn't saved. I know it's not because the control isn't bound and the control can't be bound because the form is bound to table StdDegReq which does not contain the MatricId field (see OP). The only way I could bind cboMatricId was to add MatricId to StdDegReq but then that would violate normalization rules.

I was just wondering if there was some way to fanagle the MatricId to display anyway. Because I can get an unbound textbox to display the MatricId by using a DLookup as the textbox's control source no problem. But I can't seem to do the same for a combobox.
Apr 27 '10 #14
NeoPa
32,556 Expert Mod 16PB
In that case it may help to know that what is displayed is the .Value of the ComboBox control. It's obviously a good idea if the value matches an entry in the list, so the .RecordSource should still be set to reflect the list of valid items selectable. To set the currently selected value of that ComboBox though, you need simply set the .Value in the code. Does that throw more light?

Essentially, when you need this set, have a line in your code something like :
Expand|Select|Wrap|Line Numbers
  1. ComboBox = DLookUp("MatricId", "DegReq", "DegReqId=[txtDegReqId]")
Apr 28 '10 #15
bullfrog83
124 100+
@NeoPa
Where do I set this in the code? On what event?
Apr 28 '10 #16
NeoPa
32,556 Expert Mod 16PB
Sorry. I was confusing your intelligent approach with more specific Access experience. I skipped some important information. Let me point you a little more clearly.

First start by identifying the control on your form that it will be filtered on. In the code you specify [txtDegReqId], yet earlier you referred to a ComboBox named [cboDegReqId]. Whichever is the one you need, you should create an AfterUpdate procedure (Select control; Click in the After Update property of the Properties Pane; Select the value "[Event Procedure]"; Enter the code).

The code should be something like :
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboDegReqID_AfterUpdate()
  2.     cboMatricID = DLookup(Expr:="MatricId",
  3.                           Domain:="DegReq",
  4.                           Criteria:="[DegReqId]=" & Me.[cboDegReqId] & ")
  5. End Sub
Apr 28 '10 #17
bullfrog83
124 100+
@NeoPa
That did the trick! Thanks for your help and patience!
Apr 28 '10 #18
NeoPa
32,556 Expert Mod 16PB
Not a problem.

Please come back with more if/when you need.
Apr 29 '10 #19

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

Similar topics

2
by: Georges Heinesch | last post by:
Hi. I cannot change the value of an unbound control (txtSR and txtSS) within a sub call. I explain ... my sub (SRSS_set) takes the date (type date) as input, and returns 2 values (type time). ...
0
by: Bob Bykerk | last post by:
Hyperlinks work fine when using bound controls but when I try to get one to work on an unbound control (with hyperlink? = true) I can't insert a hyperlink or use the data as a hyperlink. I have...
3
by: Trevor Hughes | last post by:
I am trying to resolve a problem I'm experiencing in Access 2000. I have an unbound control which is set be code on the open event of a form. However when I try to subsequently run some code...
1
by: Jim M | last post by:
To prevent data corruption I have replaced a memo field on my form with an unbound control on my form that I populate with a function that fills it from a memo field from my table. When the form is...
0
by: Barbara Schmidt | last post by:
Hello, if I get the data from db with sqldatasource-control, how to show this data to an unbound control, so for instance: label1.text=sqldatasourceWHAT-TO-DO-NOW Thanks Barbara
3
by: scott_baird | last post by:
Probably something simple, but it's driving me up the wall... In a report, I have an unbound control that is the total of 2 other bound controls (currency) as follows: unbound control =cash1 +...
1
by: umeshdchaudhari | last post by:
fist I filled value of drow down and GridView control. Now we find the databound of grid view control as per drow down value at time binding. ? How we find the value of control time of binding in...
0
JAMBAI
by: JAMBAI | last post by:
I am using a OLE unbound Control to Embed the word document in the form load, event like this http://support.microsoft.com/kb/209990 and When i double clicks (In Place activation), the documents...
5
by: John McAtee | last post by:
I am using Access 2007. Created a contribution database for a non-profit. Created parameter query that displays contributions for a specified time period using the "Between And " parameter. The...
4
by: beemomo | last post by:
This is my second post for the same question, hope this time I did explain more clearly about my problem. I need a report that generate the total value of projects from a few foreign currency to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.