How to Concatenate WHERE condition of OPENFORM MACRO or VBA?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mr Key
    New Member
    • Aug 2010
    • 132

    #1

    How to Concatenate WHERE condition of OPENFORM MACRO or VBA?

    Hi all!
    I have a form named Form1, from there I can open another form named frmModules by using OPEN_FORM MACRO at OnClick Event of ComandButton as follows
    Code:
     [B]OpenForm[/B]
            Form Name:      [B]frmModules[/B]
            View:           [B]Datasheet[/B]
            WHERE CONDITION:[B]="[ModID]=" & [ModuleID][/B]
            Data Mode:      [B]Edit [/B]
            Window Mode:    [B]Normal[/B]
    With this MACRO I can Open frmModules which shows the data equivalent to the one selected from Combobox ModuleID from Form1 WHERE Forms!Form1!Mod uleID=Forms!frm Modules!ModID
    Question:
    How can I CONCATENATE the WHERE CONDITIONS to include more Criteria?
    Example OPEN frmModules WHERE
    1. Forms!Form1!Mod ID=Forms!frmMod ules!ModuleID
    2. Forms!Form1!Cus tomerID=Forms!f rmModules!Custo merID
    3. Forms!Form1!Pro ductsName=Forms !frmModules!Pro ductsName
    Please help!!!
  • mshmyob
    Recognized Expert Contributor
    • Jan 2008
    • 903

    #2
    I don't use macros bu try something like so
    Code:
    "[ModID]=" & [ModuleID] & " AND [CustomerID]=" & [CustomerID] & " AND [ProductsName]='" & [ProductsName] & "'"
    cheers,

    Comment

    • Mr Key
      New Member
      • Aug 2010
      • 132

      #3
      It could work in my db, how about this & "'" on the end of that lineCode? What does it stand for?
      Is there any other alternative solution for this?

      Comment

      • mshmyob
        Recognized Expert Contributor
        • Jan 2008
        • 903

        #4
        Just enclosing strings in quotes. I assume ProductsName is a string.

        cheers,

        Comment

        • Mr Key
          New Member
          • Aug 2010
          • 132

          #5
          It works only with two Variables like
          [CustomerID]=" & [CustomerID] & " AND [ProductsName]='" & [ProductsName] & "'"
          If you add the third one it Doesnt!
          I wish I could have all three WHERE conditions!
          Help again!!!

          Comment

          • mshmyob
            Recognized Expert Contributor
            • Jan 2008
            • 903

            #6
            Doesn't work???

            You have to give me more details than that.

            Note: I assumed CustomerID was numeric - if it is text then you have to enclose that in quotes also.

            cheers,

            Comment

            • Mr Key
              New Member
              • Aug 2010
              • 132

              #7
              Thanks alot myshomb!
              Finally it works!!
              I just missed the Quotes between the field!
              Thanks again!

              Comment

              • mshmyob
                Recognized Expert Contributor
                • Jan 2008
                • 903

                #8
                You're welcome. Good luck with the rest of your project.

                cheers,

                Comment

                Working...