VBA, Openform error in where statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Soulspike
    New Member
    • Jan 2008
    • 35

    VBA, Openform error in where statement

    Hello all, I am haveing a problem with the openform method.

    I want to open a form with the where method but It gives me an error

    Run-Time error "2501"
    The Openform action was canceled

    You used a method of the DoCmd object to carry out an action in Visual basic, but then clicked cancel in a dialog box

    Can you please help me figure out what is wrong with my code
    Code:
    DoCmd.OpenForm "frm_Reporting_Defect_History", , , "dbo_GS_LMS_DEFECT_SHEETS.CUSTOMER_NAME = '" & Forms!frm_Main.cbCustomer & _
                                                        "' And dbo_GS_LMS_DEFECT_SHEETS.WO_NUMBER = '" & Forms!frm_Code_Repeat_Shoppings.[PostWorkOrderNum] & _
                                                        "' And dbo_GS_LMS_DEFECT_SHEETS.LOCOMOTIVE_ID = '" & _
                                                        Forms!frm_Code_Repeat_Shoppings.[tbLocoID] & "'"
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Hi

    I think I would rewrite the open statment like this
    Code:
    DoCmd.OpenForm "frm_Reporting_Defect_History", , , "CUSTOMER_NAME = '" & Forms!frm_Main.cbCustomer & "'  _ 
                                                         And WO_NUMBER = '" & Forms!frm_Code_Repeat_Shoppings.[PostWorkOrderNum] & "'_ 
                                                         And LOCOMOTIVE_ID = '" & _ 
                                                        Forms!frm_Code_Repeat_Shoppings.[tbLocoID] & "'"
    The reason for this, and the assumption made are as follows:-

    1) The left hand side of the boolean operator (= in this case) of the 'WHERE' clause should refer only to the field available in the 'frm_Reporting_ Defect_History' form.

    2) I assume that CUSTOMER_NAME, WO_NUMBER and LOCOMOTIVE_ID are all fields in the Record Source for 'frm_Reporting_ Defect_History' form.

    3) It is also assumed that all the forms refered to on the right hans side of the boolean operator are open!

    4) Last but not least, I assume that WO_NUMBER and LOCOMOTIVE_ID are text fields !?

    Hope this is of some help, and may give some clues as to the problem (as I have no real idea as to exaclty what the Error is specificaly caused by).


    MTB

    Comment

    Working...