ComboBox - Clear Values

Ports

Registered User.
Local time
Today, 09:54
Joined
Jun 30, 2019
Messages
64
I'm just practising my ComboBox skills and have stumbled upon this.


I have a form ("DropDowns") with two combo boxes on it: "FamilyName" and "GivenName"


What I did:


"FamilyName" ComboBox:
RowSource: points to the FamilyName record from a "Learners" table.


Code:
SELECT DISTINCT Valid_Learner.FamilyName
FROM Valid_Learner;

"GivenName" ComboBox:


Code:
SELECT Valid_Learner.GivenNames, Valid_Learner.FamilyName
FROM Valid_Learner
WHERE (((Valid_Learner.FamilyName)=[Forms]![DropDowns]![FamilyName]));
And After Update: Event Procedure:
Code:
GivenName.Requery
It's all working fine-ish. What I don't like is that when I select a different value from the FamilyName combo box, the previous GivenName value is still displayed. Is it possible to clear GivenName the moment the FamilyName has changed?
Thank you
 
use the code:

GivenName.Requery
GivenName=""
 
use the code:

GivenName.Requery
GivenName=""


Thanks, however, that the following happens:


I change the value in the FamilyName combobox:
a) GivenName field is empty
b) When I click on the GivenName comboBox, the options from the previous FamilyName selection are available
c) when I click on the GivenName combo Box AGAIN, the right options for the FamilyName are available.
d) I select a GivenName I want but it does not get stored/displayed in the combobox field.
 
that's strange.
another approach is changing the RowSource of your GivenName combo on the AfterUpdate event of FamilyName combo:
Code:
Private Sub FamilyName_AfterUpdate()
Me.GivenName.RowSource="SELECT Valid_Learner.GivenNames, Valid_Learner.FamilyName
FROM Valid_Learner
WHERE Valid_Learner.FamilyName=" & Chr(34) & Me![FamilyName] & Chr(34)
Me.GivenName.Requery
Me.GivenName = ""
End Sub
 
Please upload your DB as that does not happen IF you have coded it as you have said.?
 
Please find attached the db file. Thank you all.
 

Attachments

You put the code in the AfterUpdate event of the GivenName control.?

It needs to be in the AfterUpdate event of the FamilyName control.
 
You put the code in the AfterUpdate event of the GivenName control.?

It needs to be in the AfterUpdate event of the FamilyName control.
Thanks. That was it.
 

Users who are viewing this thread

Back
Top Bottom