Re-populate Subform textboxes on Mainform combobox update.

binbin

Registered User.
Local time
Today, 16:44
Joined
Sep 3, 2012
Messages
53
Hi everyone!

I have a combo box in a subform that AutoFills textboxes in the subform.

The subform combo box also has a Dlookup procedure on "after update" event that has a criteria on what the AutoFill procedure will populate based on the mainform textboxes that is AutoFilled by a mainform combo box.

Everything works fine, until I change the value of the Mainform combobox, which changes the value of the textboxes on the mainform from which the Subform combobox gets its criteria for the Dlookup procedure.

My problem is that the Subform combobox does not re-populates the subform textboxes when I change the value of the mainform combobox. I still need to select the same item in the subform combobox list to initiate the AutoFill procedure of the subform textboxes.

I would like to re-run the AutoFill procedure of the subform combobox when I update the main form combobox. I tried the following procedures on "afterupdate" event of mainform combobox, but did not re-populate the subform text boxes.

Forms!MainformName!SubformName!SubformComboBoxName.Requery

Forms!MainformName!SubformName.Requery

Me.SubformName.Requery

Thanks!
 
If we cannot refresh the repopulate procedure, how about refreshing or re-running the Subform.combobox DLookup procedure on Mainform.combobox update?

Thanks.
 
have you tried requery in subform event.
 
Yes I did. Its not that the Me.SubformName.Requery function is not working, it's just not enough to re-run the DLookup procedure in my Subform.Combobox.

In order for the Subform.Combobox to repopulate the textboxes based on the DLookup function, I have to choose the item again in the subform, otherwise, it will not repopulate the correct values.

This is dangerous since the user can give un-authorized discounts by choosing an account with discounts (VIP's), choose the items in the subform with all special discounts applied, then change the VIP account to a non-discounted account and because the correct values do not repopulate the correct rate, the non-discounted account, inherited the discounted rates of the VIP.

Is there a way to re-run DLookup function on my Subform.Combobox after I update my Mainform.Combobox?

Thanks.
 
Hi again!

Since maybe what I had in mind is also making you guys scratch your heads, there's probably a work around for my problem. I found an inspiration from deconstructing the northwind "Purchase Order" form. That is, to prevent the user from updating or even adding records to the subform entirely if the user attempts to change the customer combobox when the user already has added items to the subform. This is probably the best solution for problem.

I think I have the vba code responsible for that delicious procedure... however, my vba repertoire is limited to a children's color by number book.

PHP:
Private Sub Supplier_ID_BeforeUpdate(Cancel As Integer)
    'Changing Suppliers with defined line items requires some decisions
    If PurchaseContainsLineItems() Then
        If Not MsgBoxYesNo(ChangeSupplierWarning) Then
            Cancel = True
        ElseIf PurchaseOrder_ContainsPostedInventory() Then
            MsgBoxOKOnly CannotRemovePostedItems
            Cancel = True
        ElseIf Not FRemovePurchaseLineItems() Then
            MsgBoxOKOnly ErrorRemovingPurchaseLineItems
            Cancel = True
        End If
    End If
End Sub

I've tried to deconstruct this even further, however, I really don't know what "PurchaseContainsLineItems()" after the "IF" means, is that a command? It seems like a criteria, but I can't find it in northdwind. :banghead:

The Message boxes I think I get, but I don't know where to look for the

PHP:
MsgBoxYesNo(ChangeSupplierWarning)

I maybe making some of you guys raise your hands in the air, but I really need help. Maybe a hint if an answer is too obvious... :rolleyes:

Thanks again for taking the time to read this, for the time being, I'll google the hell out of it...
 
This is getting too complicated, I cannot seem to get it to work in my form...

I guess to simplify the problem, how do I delete the records in the subform if the user changes a value in the mainform combo box?

Update: Solved it! I think...
 
Last edited:

Users who are viewing this thread

Back
Top Bottom