not in list property

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lee123
    Contributor
    • Feb 2007
    • 556

    not in list property

    well this is a tough cookie this property, i just keep on getting a runtime error
    with this can anyone tell me what is wrong with this code.

    Code:
    Private Sub PRODUCTCOMBO_NotInList(NewData As String, Response As Integer)
        
        If MSGBOX("THIS ISN'T IN THE LIST,DO YOU WANT TO ADD THIS?", vbYesNo + vbQuestion, "PLEASE RESPOND!") = vbYes Then
            DoCmd.OpenForm "PRODUCTF", DATAMODE:=acFormAdd, WINDOWMODE:=acDialog, _
            OpenArgs:=NewData
        If ("PRODUCTF") Then
            Response = acDataErrContinue
            Docmd.Close acform, "productf"
        Else
            Response = acDataErrContinue
        End If
    Else
            Response = acDataErrContinue
        End If
        
    End Sub

    i don't understand why it keeps on saying runtime error with this because i want to add items in my productcombo.Ex plain to me whats happening here and why the runtime?

    lee123
  • JConsulting
    Recognized Expert Contributor
    • Apr 2007
    • 603

    #2
    Originally posted by lee123
    well this is a tough cookie this property, i just keep on getting a runtime error
    with this can anyone tell me what is wrong with this code.

    Code:
    Private Sub PRODUCTCOMBO_NotInList(NewData As String, Response As Integer)
        
        If MSGBOX("THIS ISN'T IN THE LIST,DO YOU WANT TO ADD THIS?", vbYesNo + vbQuestion, "PLEASE RESPOND!") = vbYes Then
            DoCmd.OpenForm "PRODUCTF", DATAMODE:=acFormAdd, WINDOWMODE:=acDialog, _
            OpenArgs:=NewData
        If ("PRODUCTF") Then
            Response = acDataErrContinue
            Docmd.Close acform, "productf"
        Else
            Response = acDataErrContinue
        End If
    Else
            Response = acDataErrContinue
        End If
        
    End Sub

    i don't understand why it keeps on saying runtime error with this because i want to add items in my productcombo.Ex plain to me whats happening here and why the runtime?

    lee123

    Maybe a working example will help out.

    [code=vba]
    if msgbox(newdata & " is not a current value. Add it?",vbyesno)=v byes then
    Response = acDataErrAdded
    combo1=newdata
    DoCmd.OpenForm "formname", acNormal, , , , acDialog
    docmd.gotorecor d acform,"FormNam e",acnewrec
    Forms!FormName! Field = newdata
    else
    sendkeys "{Esc}" 'clears combo
    response = acDataErrContin ue
    end if

    [/code]

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Originally posted by lee123
      well this is a tough cookie this property, i just keep on getting a runtime error
      with this can anyone tell me what is wrong with this code.

      Code:
      Private Sub PRODUCTCOMBO_NotInList(NewData As String, Response As Integer)
          
          If MSGBOX("THIS ISN'T IN THE LIST,DO YOU WANT TO ADD THIS?", vbYesNo + vbQuestion, "PLEASE RESPOND!") = vbYes Then
              DoCmd.OpenForm "PRODUCTF", DATAMODE:=acFormAdd, WINDOWMODE:=acDialog, _
              OpenArgs:=NewData
          If ("PRODUCTF") Then
              Response = acDataErrContinue
              Docmd.Close acform, "productf"
          Else
              Response = acDataErrContinue
          End If
      Else
              Response = acDataErrContinue
          End If
          
      End Sub

      i don't understand why it keeps on saying runtime error with this because i want to add items in my productcombo.Ex plain to me whats happening here and why the runtime?

      lee123
      This is not the typical approach for implementing the NotInList Property. Customarily, the NewData Value is added to the Record Source of the Combo Box by creating a Recordset based on the Table/Query and adding it programmaticall y. Any deviation from this approach may open the door for potential Errors.

      Comment

      • lee123
        Contributor
        • Feb 2007
        • 556

        #4
        yea i got this out of a book i bought did know but i'll try yours thanks

        lee123

        Comment

        • missinglinq
          Recognized Expert Specialist
          • Nov 2006
          • 3533

          #5
          We've been concentrating on the NotInList code for the calling form, but what's going on in the Form_Load event of the second form? Could the problem be in how the OpenArgs/NewData is being assigned at that end ?

          Linq ;0)>

          Comment

          • lee123
            Contributor
            • Feb 2007
            • 556

            #6
            well i tried your code. question, this code doesn't save the item in the list does it? when i executed the code and typed something in the combo box it worked fine but after i closed the form (productf) it gave me a error that said the "productf form isn't open" to give you an idea what im doing is this. i have a order form, product form. in the order form i have a subform (orderdetail form) that i put a combobox in it to add items to the subform (orderdetail) so when i have something that isn't in the list instead of going to the product form i would like to type it in the combobox named (productcombo) and have it open the form (new record) so i can add it to my list of products well i hope this explains it.

            lee123

            Comment

            • missinglinq
              Recognized Expert Specialist
              • Nov 2006
              • 3533

              #7
              I'll ask you again; how is the OpenArgs/NewData (the new product you've entered into in the combobox) being assigned to the product field in the new record on the form "productf?" The code JConsulting posted as an example does it in Line # 6, but I see nothing in your code to do this! Is it handled in the Form_Load of the "productf" form?

              You're getting the error about the form productf "not being open" because you've closed it manually, after entering whatever in the new record, then you have code to close it again!

              Linq ;0)>

              Comment

              • lee123
                Contributor
                • Feb 2007
                • 556

                #8
                now, now take it easy. like i said in the previous question i got this example out of a book. that being said as far as the openarg/newdata, what they have in this book is this:

                Code:
                if isloaded("formname") then
                    response=acdataerradded
                    docmd.close acform, "formname"
                so i tried to make it work for me the code i posted is what they have in this book if i didn't post it all im sorry. but when i tried this code they have in the book it would except this line of code so i left it out or tried to go around it i took there example and changed there form name to mine and hoped it worked.

                lee123

                Comment

                • lee123
                  Contributor
                  • Feb 2007
                  • 556

                  #9
                  i see i typed in the wrong code in mine i have:

                  Code:
                  if ("productf") then
                     response=acdataerrcontinue
                   docmd.close acform, "productf'
                  when it is suppose to be:

                  Code:
                  if ("productf") then
                     response=acdataerradded
                   docmd.close acform, "productf'
                  thats why you didn't see it in mine?

                  lee123

                  Comment

                  • missinglinq
                    Recognized Expert Specialist
                    • Nov 2006
                    • 3533

                    #10
                    You also have if ("productf") then instead of if Isloaded("formn ame") then which is why, I suspect, you're getting the errror about the form not being open. The code from your book checks to see that the form is loaded before closing it, you code doesn't.

                    As I said before, the code you posted (that you got from your book) hasn't made any provision for assigning the NewData to the appropiate field of the form/record you're opening. I think you really need to refer back to this book and read thru it concerning this routine a little more carefully. I suspect that you've probably made additonal errors in going from the book to your ccode editor.

                    Linq ;0)>

                    Comment

                    • lee123
                      Contributor
                      • Feb 2007
                      • 556

                      #11
                      well, i altered the code and it works know thanks anyway.

                      lee123

                      Comment

                      • missinglinq
                        Recognized Expert Specialist
                        • Nov 2006
                        • 3533

                        #12
                        Glad you got it figured out! Please post your final code so that others researching this or similar probelms in the future may benefit.

                        Linq ;0)>

                        Comment

                        Working...