Results 1 to 8 of 8

Thread: Requery problem

  1. #1
    Join Date
    Jan 2008
    Posts
    54

    Unanswered: Requery problem

    I have a pop up form consisting of an option box named OptWeight. In this option box are 2 checkboxes 500g/bottle and another 1000g/bottle. Also on this form is an unbound text box named txtTotalWeight. This form pops up when the main form quantity (txtQty) is entered or edited. After selecting the checkbox I would like the total weight reflected in the txtTotalWeight text box.
    The total weight is obtained by multiplying its quantity on the main form and 500g/bottle or 1000g/bottle on the pop form depending on the checkbox selected.

    Private Sub Check3_LostFocus()
    Me.txtTotalWeight = Forms!frmMain.txtQty * 500
    Me.Requery
    End sub

    Private Sub Check5_LostFocus()
    Me.txtTotalWeight = Forms!frmMain.txtQty * 1000
    Me.Requery
    End sub

    What I would like to see a immediate result in the total weight textbox when I had checked 500g/bottle or 1000g/bottle checkbox. However the result only appears after I have clicked the total weight text box or when I press the F6 key.

    Can somebody please help?
    Thanks

  2. #2
    Join Date
    Sep 2006
    Location
    Surrey, UK
    Posts
    995
    Provided Answers: 2
    First off, don't use check boxes. Your selections (as you've explained it here) are mutually exclusive, so you should either go with a combo box with two values or an option group.

    Secondly, to see the result sooner, you need to place the code on the "OnChange" event of the control(s) concerned, and add the line "Me.Repaint" to force the calculation to be displayed.

  3. #3
    Join Date
    Jan 2008
    Posts
    54
    Thank you. I will give it a try.

  4. #4
    Join Date
    Jan 2008
    Posts
    54
    I tried both the combo box and option group. The combo box works without repainting. Of course, the main form is opened.

    Private Sub cboWt_Change()
    Me.txtTotalWeight = Forms!frmMain.txtQty * Me.cboWt.Column(0)
    End Sub

    For Option Group I still have to click the Total Weight text box to see the result. Besides the option group does not have an on change event. Only the Total weight unbound text box does.

    How do you do it with an option box and what events do you use to accomplish that?

    Thanks

  5. #5
    Join Date
    Sep 2006
    Location
    Surrey, UK
    Posts
    995
    Provided Answers: 2
    For option and check boxes, use the "OnClick" event. However, if the combo box worked, stick with that!

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    to set the value of a control place some code in the forms on current event to set it for values that already exist in the db
    I'd rather be riding on the Tiger 800 or the Norton

  7. #7
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    As a rule, the OnChange event of the combobox shouldn't be used in code, but rather the AfterUpdate event. The problem is that the OnChnage event of a combobx will fire every time user type a character in if they try to use the AutoExpand feature, which can lead to mistakes.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  8. #8
    Join Date
    Jan 2008
    Posts
    54
    Points taken. Thanks for your inputs.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •