Hello Ken,
The first combo box is called Client. Its Control Source is the Client
field in a table called tblPlan.
That Clent field looks up another table called tblClient.
Therefore the Row Source of the Client combo box on the form is SELECT
tblClient.ClientID, tblClient.Client FROM tblClient ORDER BY
tblClient.Client;
I can make a selection in the combo box of any of the Clients present in
the Client table.
The column count of the combo box is 2 but the Bound Column is 1. Column
1 is an AutoNumber so I think that means the Client field is numeric.
A client visits this Financial Planning business to have a financial plan
designed for them. Some plans are short term proposals so the client
comes back in say 6 months and wants another plan designed.
The form causing all the grief here is called frmNewPlan. As well as the
Client combo box there is a Combo box called PlanWriter.
The people who require this database would like the PlanWriter combo to
default to the whoever the PlanWriter was who most recently designed a
plan for the Client selected in the Client combo box.
I am able to determine this by a series of 3 queries on queries.
Using DLookUp("MaxOfPlan_Writer_ID
","qryMost_Recent_Planwriter_3","[Client]=Form![Client]") in a hidden
text box, I can display the numeric ID of the PlanWriter.
So, I'm fairly sure my logic is correct.
I need to be able to make the PlanWriter combo display the PlanWriter
name matching the ID displayed in the text box.
The PlanWriter combo is similar to the Client combo in that its Control
Source is a field in tblPlan and its Row Source is
SELECT tblPlanWriter.Plan_Writer_ID, tblPlanWriter.Plan_Writer,
tblPlanWriter.Active FROM tblPlanWriter WHERE
(((tblPlanWriter.Active)=Yes)) ORDER BY tblPlanWriter.Plan_Writer;
with a column count of 2 and a bound column of 1.
I've tried all the methods suggested in this forum, for example,
PlanWriter combo = TextBox in the After Update event of the Text box but
so far the PlanWriter combo remains blank. All the answers offered by
some very kind people seem to be saying to me, "This is really straight
forward stuff, whats the matter?"
But still, no luck.
Bob
Ken Snell (MVP) said:
Bob -
I'm a bit confused. If you have an expression for the first combo box's
Control Source property, then you're not going to be able to actually
make a selection in that first combo box -- and thus the AfterUpdate
event of that combo box will not occur, and thus the code will not run
to set the second combo box to the desired value.
Normally, when using "matched" combo boxes, you want to be able to make
a selection in the first combo box so that the second combo box is "set"
in some way based on the selection made in the first combo box.
Perhaps it would be good if we step backwards a few steps and let you
tell us exactly what you're wanting to accomplish on this form? Also, is
the Client field a numeric field or a text field?
--
Ken Snell
<MS ACCESS MVP>
Thankyou Ken,
I now have the following in the AfterUpdate event of the first combo
Private Sub Default_Planwriter_AfterUpdate()
Me.PlanWriter.Value = _
DLookup("Plan_Writer", "qryDefault_Planwriter", "[Client]=" & _
Me.Default_Planwriter.Value)
End Sub
The control source of the first combo (Default_Planwriter) remains
=DLookUp("Plan_Writer","qryDefault_Planwriter","[Client]=Form![Client]")
which is a String
I have deleted the Control source of the second combo (PlanWriter) so
now it is unbound but its Row Source remains
SELECT tblPlanWriter.Plan_Writer_ID, tblPlanWriter.Plan_Writer FROM
tblPlanWriter;
The primary key here, Plan_Writer_ID is a AutoNumber so does that mean
this sql is returning a number.
If so, do I need to convert my text string to a number or maybe, my
number to a string.
Bob
I'm headed out of town for a week, so I'm hoping that another person
will be able to pick up for me in this thread; I apologize.
But I did note an error in my generic code. The code should be for the
first combo box's After Update event:
Private Sub FirstComboBoxName_AfterUpdate()
Me.SecondComboBoxName.Value = _
DLookUp("Plan_Writer","qryDefault_Planwriter","[Client]=" & _
Me.FirstCombBoxName.Value)
End Sub
--
Ken Snell
<MS ACCESS MVP>
The user doesn't select the value in the first
combo(cboDefault_Planwriter). It is calculated by a DLookUp that
finds the most recent Plan writer for the client that a user does
select in another combo box (cboClient)
The second combo (cboPlanwriter) is bound to a table so that the user
can choose another planwriter if the one returned by
cboDefault_Planwriter is not suitable
I'll try removing its control source and post back after work.
Thanks
Bob
You need to set the Value of that second combo box to the desired
"default", and not use an expression in its ControlSource property.
Assuming that you want this to be done after the user selects the
value in the first combo box (what is its name?), you can use the
AfterUpdate event of that first combo box to do this (the code
example assumes that the Value of the first combo box is a numeric
value, not a text string value):
Private Sub SecondComboBoxName_AfterUpdate()
Me.SecondComboBoxName.Value = _
DLookUp("Plan_Writer","qryDefault_Planwriter","[Client]=" & _
Me.FirstCombBoxName.Value)
End Sub
--
Ken Snell
<MS ACCESS MVP>
Hi,
I have a problem I'm trying to overcome regarding just one form
which gets
its data from 1 table.
I'm trying to set the default value of a combo box to be the same
as another
combo box on the same form.
The scenario is:
I have a form for entering info about financial planning Statements
Of
Advice.
Each client has a Plan Writer prepare their plan.
To find the plan writer that last prepared the plan for a client I
have a
combo box with a DLookUp as its Control Source.
=DLookUp("Plan_Writer","qryDefault_Planwriter","[Client]=Form![Client]")
I'm using a query so as to find the most recent record for a
client.
Works wonderfully! but this combo can only be used for display.
Now the part thats causing me grief.
I want the value returned by that DLookUp to be the default value
for
another combo box with the Row Source of
SELECT tblPlanWriter.Plan_Writer_ID, tblPlanWriter.Plan_Writer FROM
tblPlanWriter;
The second combo must remain editable so that another plan writer
can be
chosen if necessary
I've played around with all sorts of things, using the Expression
Builder,
borrowing bits of code from all over the net, Before Update, After
Update.
I cant find anything on the internet the same as what I'm
attempting, which
makes me wonder if what I want is even possible.
Thankyou
Bob