Results 1 to 9 of 9
  1. #1
    Rgaming is offline Novice
    Windows 10 Access 2007
    Join Date
    Oct 2017
    Posts
    9

    Code to input data from form into table

    I have a form of which when I click on a button, I want the value of a text box on the form to be placed into a table.
    So far, once the button is pressed it opens up the table on a new record. However, I am not sure how to add the data into the table.


    Next_Appointment_ID (on the form) stores the value that I want to be inputted into the table
    Payment_ID is the field on the table that I want the data to be saved to.



    Code so Far:


    Private Sub Command46_Click()
    DoCmd.OpenTable "Payment", acViewNormal, acEdit
    DoCmd.GoToRecord , , acNewRec
    Payment_ID = Next_Appointment_ID
    End Sub

    Help me Please!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    you type it in.
    if you have a form with all the fields on the form, just type into the boxes. Its that simple. No programming needed.

    Access can automatically create a form with all fields on the form. (use the wizard)

  3. #3
    Rgaming is offline Novice
    Windows 10 Access 2007
    Join Date
    Oct 2017
    Posts
    9
    I understand what you are saying as I have done this already.
    Using the appointment table on my database I have created this form of which I can edit and update data onto the Appointments table. However, on this form, i also need it to store the value of a text box to a different table (i.e The payment table)
    Do you know the code that appends data to a table?

  4. #4
    ohmydatabase's Avatar
    ohmydatabase is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2017
    Posts
    79
    I don't use the features built into Access that make forms out of your tables, I find them crude and usually not very useful. So even when I'm only displaying information I start with a blank form and work my up.

    With that being said, you can add code to the form that can do this. On the OnChange Event of that specific textbox, you can define the current value of the contents of the textbox (i.e. currentText) to some variable (which would be dimensioned form-wide) when you click a button (or whatever) to update your data in the Appointments table, you can also execute a bit of code that adds currentText to your Payment Table. I recommend using the DAO object to do this.

    You'll need to:
    - assemble an SQL Query (sqlStr = "INSERT INTO [tblPayments](Field1) VALUES('" & currentText & "');"
    - you can then use CurrentDb.Execute (sqlStr)

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    For clarity it would be helpful to readers if you could show us a jpg showing all tables and relationships in your database.

  6. #6
    Rgaming is offline Novice
    Windows 10 Access 2007
    Join Date
    Oct 2017
    Posts
    9
    Thanks for all the replies, however, I am still not underestanding what I have to do. (This is the first database I've ever created)
    I will make a video within the next couple days to show you what my problem is.

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  8. #8
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 10 Access 2016
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,538
    If you have a control on your form that you wish to update to a different table, then you will probably have to put that control on a sub-form and bind that sub-form to your different table.
    Last edited by alansidman; 10-11-2017 at 02:04 PM. Reason: typo correction

  9. #9
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Or the form is based on a query, not a table, and that query includes all necessary fields from whatever tables, and that query is updatable. Then no code required. You input the textbox value and it's automatically input into the table.
    IMHO, using a wizard to create a form is OK as long as you don't settle for the default names Access gives to the controls.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 09-25-2016, 01:43 PM
  2. Replies: 6
    Last Post: 04-04-2015, 08:10 AM
  3. Replies: 6
    Last Post: 02-09-2015, 12:17 PM
  4. Replies: 1
    Last Post: 05-03-2012, 02:25 PM
  5. Replies: 4
    Last Post: 07-17-2011, 06:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums