Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing a form control 2

Status
Not open for further replies.

nag9127

Technical User
Mar 15, 2007
76
US
I have a from which has 2 combo boxes. The list for the second box is dependent upon the first box selection. The combo boxes are working properly. I have an unbound field which performs a DLookup based on the selection in the second combo box. If selections have already been made and the fields are populated with information, when I click the drop down on the first combo box to change the main record, my second combo box immediately clears and then provides a revised lookup based on the new value selected in my first combo box. However the control performing the DLookup based on the second combo box does not clear inspite of the fact that the combo box on which the DLookup is based is now blank and contains a lookup pertaining to the changed value in combo box #1. I can't seem to successfully blank the field. I've tried undo and requery, but with no success. Thanks for any help!
 
in after update of combo1

me.delookupcontrolname=
 
That is an approach I have tried. When I apply that code, I get an error that says "I can't assign a value to that object". Even if I use a variable to accomplish that, rather than assigning the value directly, I get the same error.
 
you must have the Control Source of the control as
Code:
= dlookup("fieldnmae" ,"tablename",wherecondishion)

remove that

and in after update of combo2

put
Code:
me.controlname= dlookup("fieldnmae" ,"tablename",wherecondishion)
 
What about Me.ReCalc ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
None of these approaches seem to work. And Access 2000 doesn't appear to support recalc as a method. I just don't understand how the second combo field can requery successfully to a blank field after the first combo box is modified from a prior selection (there is a me.combo2.requery statement in the before update event of combo1), but the fields dependent upon the second combo box will not requery the old results away.
 
This is what I did and it works in access 2007
Code:
Private Sub Combo0_Click()
    Combo2.Requery
    Combo2 = ""
    Text4 = ""
End Sub

Private Sub Combo2_Click()
   Text4 = DLookup("productname", "tblneedtoorder", "productname ='" & Combo2.Value & "'")
End Sub

ck1999
 
Well, I got it to work by using the value method which I hadn't considered. I also took the DLookup parameter out of the control source for the field and stuck it in the After Update event of the second combo box. Taking the Dlookup out of the field control source property and using the value method in the criteria statement then allowed me to assign a value of "" to the control in the BeforeUpdate event of the first combo box. Previously it was producing that "can't assign value to that object" error. I think the combination of these changes eliminated that data conflict. Thanks to everyone for their persistence and testing!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top