Results 1 to 7 of 7
  1. #1
    themushroomking is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    23

    Take value from a form and write to a table as a new record

    Hi folks! Kindly asking for some guidance because im stuck on something since forever. Im a novice Accesseroid



    I have a MainForm with an ID. And a SubForm that searches in some excel files and returns the search in fields on the subform.
    When the search results are correct, i want to add the "item" to the ItemsTable and link it to the MainForm ID.

    I managed all that. I can do the search, return values in my form fields and save them in the table (relation) with the current MainForm ID.

    My problem: I would like to keep adding items to the table, but it just overwrites the data in the table every time. (logically because its the same form field over and over).

    What VBA do i need to add to my code to save the information as a NEW record, instead of overwriting???


    Forms!inboundreturns.Form.Item.Value = Me.Item.Value

    Thanks in advance guys!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    when you get to the last field on the form and press enter,
    it goes to the 1st field on the next record. (if you did not alter form settings)

  3. #3
    themushroomking is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    23
    Hi Ranman, thanks for the swift reply!

    In any case, sure i would say.

    In my case i have a MainForm with an ID and i want to stay on that current ID and add items to it.
    For a simple example: See it as a customer table, that has a relation to the sold items table.
    Currently i am on the customer table and im adding items with a command button.
    The code works fine, but i want it to put the item on a new row. (Currently it just overwrites)

    So i am not making new records. But im adding items to the current record in a different table thats relational

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    if the relation is set correctly, it should allow you to add many records.
    if not, you are stuck on 1 record only.

  5. #5
    themushroomking is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    23
    Quote Originally Posted by ranman256 View Post
    if the relation is set correctly, it should allow you to add many records.
    if not, you are stuck on 1 record only.

    I should ofcourse, but its just overwriting what i have.
    What about my code up there? Can i somehow just tell it to go to a new record first?

    By adding something like AddNewRec or something like that??

  6. #6
    themushroomking is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    23
    UPDATE:

    Looking at it, i see the problem:

    The field on my form just gets updated every time. My code is wrong!

    How do i take the value from my search form (my search results) and send them to the table with a command button?

    Forms!inboundreturns.Form.Item.Value = Me.Item.Value

    Im addressing the Form in this case. How can i say something along the lines of:

    Table!inboundreturns_items.item.value = Me.item.value



  7. #7
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by themushroomking View Post
    In my case i have a MainForm with an ID and i want to stay on that current ID and add items to it.
    For a simple example: See it as a customer table, that has a relation to the sold items table.
    Currently i am on the customer table and im adding items with a command button.
    The code works fine, but i want it to put the item on a new row. (Currently it just overwrites)

    So i am not making new records. But im adding items to the current record in a different table thats relational
    What you are saying is very confusing.

    One way:
    Using your example, you have a main form bound to the customer table (I always use a query). You want to add items to the sold items table for the selected customer. So you need a sub form, bound to the "sold items" table (should not use spaces in object names).
    The main form/sub form would be linked by the Link Master field and the Link Child field.
    No code necessary.

    Another way:
    A button that has code to execute an append query to the sold items table. Would have to/like to see your current button code.

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

Similar Threads

  1. Replies: 10
    Last Post: 05-17-2017, 02:06 PM
  2. Replies: 2
    Last Post: 03-13-2015, 07:52 AM
  3. Write record to table
    By NISMOJim in forum Programming
    Replies: 10
    Last Post: 12-04-2011, 02:22 PM
  4. Replies: 3
    Last Post: 02-01-2011, 07:15 AM
  5. Replies: 1
    Last Post: 06-24-2010, 08:08 AM

Tags for this Thread

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