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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update combo box

Status
Not open for further replies.

weezles

Technical User
Jul 18, 2003
81
GB
Hi folks

I have 2 tab pages, each containing a sub form. Each sub form contains a combo box. I want the contents of cbo2 to be dependant on the selection in cbo1. cbo2's row source is set to a query which uses the current value of cbo1. This works fine for the first record but does not update cbo2 in subsequent records. How do i do this?

Thanks

Lou
 
How are ya weezles . . . . .

In the AfterUpdate Event for cbo1, add code that Requeries cbo2.

TheAceMan [wiggle]

 
OK weezles . . .

Since your cbo2 in on a different subform, you can't directly reference it. You'll have to shift the focus to that subform and then reference; Example below:

Code:
Dim frm As Form, sfrm As Form, ctl As Control
   
   Set frm = Forms!YourMainFormName
   Set ctl = frm!SubFormNameOfcbo2
   Set sfrm = frm!SubFormNameOfcbo2.Form
   
   frm.SetFocus
   ctl.SetFocus
   sfrm!cbo2Name.Requery
   
   Set sfrm = Nothing
   Set ctl = Nothing
   Set frm = Nothing


TheAceMan [wiggle]

 
weezles . . .

Although the above code will do the job, there's some unecessary schema in the code. Ya see . . . for some reason, I was thinking of setting the focus to cbo2. This is not necessary. Corrected code follows:

Code:
Dim frm As Form, sfrm As Form
   
Set frm = Forms!YourMainFormName
Set sfrm = frm!SubFormNameOfcbo2.Form
   
sfrm!cbo2Name.Requery
   
Set sfrm = Nothing
Set frm = Nothing



TheAceMan [wiggle]

 
hey Ace

thanks heaps, just what i needed

Lou
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top