ComboBox - Clear Values (1 Viewer)

Ports

Registered User.
Local time
Today, 08:14
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
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:14
Joined
May 7, 2009
Messages
19,248
use the code:

GivenName.Requery
GivenName=""
 

Ports

Registered User.
Local time
Today, 08:14
Joined
Jun 30, 2019
Messages
64
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.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:14
Joined
May 7, 2009
Messages
19,248
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
 

Gasman

Enthusiastic Amateur
Local time
Today, 16:14
Joined
Sep 21, 2011
Messages
14,485
Please upload your DB as that does not happen IF you have coded it as you have said.?
 

Ports

Registered User.
Local time
Today, 08:14
Joined
Jun 30, 2019
Messages
64
Please find attached the db file. Thank you all.
 

Attachments

  • test1.accdb
    480 KB · Views: 31

Gasman

Enthusiastic Amateur
Local time
Today, 16:14
Joined
Sep 21, 2011
Messages
14,485
You put the code in the AfterUpdate event of the GivenName control.?

It needs to be in the AfterUpdate event of the FamilyName control.
 

Ports

Registered User.
Local time
Today, 08:14
Joined
Jun 30, 2019
Messages
64
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

Top Bottom