Trying to make a button on a form add information into a table from textboxes.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • D347HxD
    New Member
    • Oct 2013
    • 8

    Trying to make a button on a form add information into a table from textboxes.

    Hello, I have been working on a database and so far it's going well. I have 14 text boxes that are hooked up to a button that searched a query (which is attached to a table) for what you searched. It works perfectly... though I'd like to add one more feature to this database; and that is an add button. Where if you enter information into those same text boxes, and click the add button instead of the search button it'll add a field with all that information you entered into the table, which lets the query see it and you can search for it at later times.

    To see exactly what I mean in front of you, to get a better understanding of what is going on and such, the download is below to my database.

    Please ignore CustomersT as it was me fooling around with tables and is 100% not needed.

    Table name: OrderT
    Query Name: SearchQ
    Form: SearchF
    Textbox Names:
    - BusinessName
    - DateOfPurchase
    - CutplanDueDate
    - HardwareSpecs
    - PurchaseOrder
    - OrderName
    - EngineerDueDate
    - MaterialSpecs
    - HardwareDueDate
    - PurchaseSupplie r
    - OrderDesc
    - ProjectComplete
    - CutplanCode
    - HardwareComplet e
    FieldNames:
    All same as above text box names.
    Button Name: Command344

    Windows 7
    Windows Access 2013

    If you need more information, please ask.
    Attached Files
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You really should not allow your users to create fields in your tables. It will quickly become a nightmare. If you want to use a comment field or allow the users to add tags to a record by using another table, then you can do that. But never allows users to change the database structure.

    Comment

    • D347HxD
      New Member
      • Oct 2013
      • 8

      #3
      Well it's more of a way to make it easier for the user to edit it, as the database will have a log on feature that only administrators can use. Either way we will be adding data to the database, I just want to have this feature so everything is easier than having to go to the direct source to add the data each time.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Well, if it's only being used by administrators, then to add a column you can run an ALTER TABLE ADD command.
        Code:
        ALTER TABLE tablename ADD column specification

        Comment

        • D347HxD
          New Member
          • Oct 2013
          • 8

          #5
          Where would I put that command in? Under the OnClick event on the button?

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            That's not the full command/code. The full code depends on your database. But you can put it wherever you want the code to run.

            Comment

            • D347HxD
              New Member
              • Oct 2013
              • 8

              #7
              Never mind, I looked into the Alter Table Add command and it isn't what I need, but it's close. What I am looking for is a command that lets me add data to the table, not add new columns to the table. If that makes sense (if not, please say and I'll take pictures describing what I mean)

              Comment

              • Rabbit
                Recognized Expert MVP
                • Jan 2007
                • 12517

                #8
                Then you're looking for the INSERT INTO command.

                Comment

                • D347HxD
                  New Member
                  • Oct 2013
                  • 8

                  #9
                  Okay, will look into it and will report back!

                  Comment

                  • D347HxD
                    New Member
                    • Oct 2013
                    • 8

                    #10
                    Seems simple. How would I add to this command to take the data from the text boxes for the data being added to the table?

                    Code:
                    INSERT INTO table_name (column1,column2,column3,...)
                    VALUES (value1,value2,value3,...);
                    The values is what I need the text boxes to enter the data for.

                    Comment

                    • Rabbit
                      Recognized Expert MVP
                      • Jan 2007
                      • 12517

                      #11
                      Well, normally you rarely have to use an insert. Is there a reason you're using an unbound form instead of one bound to the table? If you bind it to the table it will insert automatically.

                      Comment

                      • D347HxD
                        New Member
                        • Oct 2013
                        • 8

                        #12
                        It isn't bound because I don't want it to insert automatically unless the add button is pressed. The search button also uses the textboxes to search the subform attached to the query. I didn't need them bound for the search button, so I never did.

                        Comment

                        • Rabbit
                          Recognized Expert MVP
                          • Jan 2007
                          • 12517

                          #13
                          In that case, you can use VBA to call a query that does the insert.

                          Comment

                          • D347HxD
                            New Member
                            • Oct 2013
                            • 8

                            #14
                            How would I do that (really new to vba and access)

                            Comment

                            • Rabbit
                              Recognized Expert MVP
                              • Jan 2007
                              • 12517

                              #15
                              In that case, you'll want to look into an Access tutorial before taking on a project like this. Try this one out: http://www.functionx.com/vbaccess/Lesson01.htm

                              Comment

                              Working...