Code updates combo box but doesn't update linked subform

cbsull

New member
Local time
Today, 15:17
Joined
Feb 21, 2006
Messages
8
I have two forms (FormA, FormB) with combo boxes (cboA, cboB) that control the record being shown in the subforms (SubformA, SubformB). I have written the following code and attached it to the "AfterUpdate" function on the combo boxes and it updates the subform perfectly.

Private Sub cboA_AfterUpdate()
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[CICustomerID] = " & Str(Nz(Me![cboA], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

Here's my problem....

I have a button on FormA that, when clicked, opens FormB, assigns the value in cboA to cboB and closes FormA. Here's that code:

Private Sub FormA_Button_Click()
Dim combovalue As Double

combovalue = Forms![FormA]![cboA]
DoCmd.Close acForm, " FormA "
DoCmd.OpenForm "FormB", acNormal, "", "", , acNormal
Forms![ FormB]![cboB] = combovalue

End Sub

Unfortunately, I can not figure out how to have SubformB automatically update based on the new value assigned by code to cboB.

I've tried .Requery, "After Update/Change/Dirty/etc." on cboB, "OnOpen" on FormB, and moved the code from cboB "AfterUpdate" to ButtonA "AfterClick" and nothing seems to work.

I need the user to use buttons to navigate through various forms displaying information for the same record. I also need to give the user the option to switch the record using the combo box. Does anyone know how to do this? Is it possible to use code to update the value in a combo box and then have the record in the subform automatically change?

Any help would be greatly appreciated!
 
Last edited:
Pat's idea seems good, but I'm just curious
why won't this work?

Private Sub FormA_Button_Click()
Dim combovalue As Double

combovalue = Forms![FormA]![cboA]
DoCmd.Close acForm, " FormA "
DoCmd.OpenForm "FormB", acNormal, "", "", , acNormal
Forms![ FormB]![cboB] = combovalue

Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
rs.FindFirst "[CICustomerID] = " & combovalue
If Not rs.EOF Then Me.Bookmark = rs.Bookmark


End Sub
 
Pat and DB7,

Thanks for your help so far with this. Unfortunately, neither solution has worked. I have simplified my database to only include 2 Forms, 2 Subforms, and code for the relevent buttons and combo boxes (Pat's code is there now). Do you mind taking a look at this to determine if maybe I made a mistake interpreting your instructions or if you can determine how to fix it?

Thanks so much! I've been trying to figure this out for over a week and I'm going crazy! :eek:
 

Attachments

2 small points,
Private Sub Form_BeforeInsert(Cancel As Integer)
Me.CICustomerID = Forms![NewFrm_qry_CusIns_KeyEvents]![cmbo_KeyEvents]

End Sub


Private Sub Employee_Button_Click()
DoCmd.Close acForm, "NewFrm_qry_CusIns_Employee"
DoCmd.OpenForm "NewFrm_qry_CusIns_KeyEvents", acNormal, , "CICustomerID = " & Me.[CICustomerID]
End Sub
 
Forgot to add, You don't have a field called "SalariedRatio", why are you surprised, you're getting an error?
 

Users who are viewing this thread

Back
Top Bottom