Results 1 to 9 of 9
  1. #1
    zero5587 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jan 2016
    Posts
    4

    Post How can i make a button that fills a Table

    Hi

    is it possible to make a button that fills a field in a table .

    so when i press the Button it should put a text into a field in my table.

    thanks

  2. #2
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Assuming the table to be updated is the record source for the form, and that the field to be updated is a control on the form, it's easily done with VBA.

    Use the On Click event of the button to add the text to the form field:

    Me![myformcontrol] = "Some text..."

    It's a bit trickier if the table to be updated is not the form recordsource, but it's still easy.

  3. #3
    zero5587 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jan 2016
    Posts
    4
    Hi thank you very much

    the table isnīt the form recordsource so what should i do

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    OK - you will have to use SQL to update the relevant table, but you will need some additional information to identify which record in the table is to be updated, in addition to the new value.

    You would do something like this, again in the On Click event:

    Code:
    Dim SQL as string
    SQL = "Update tablename set fieldname1= 'some text...' where fieldname2 = " & me![formcontrol]
    currentdb.execute SQL, dbfailonerror
    Where:

    tablename is the table containing the record to be updated
    fieldname1 is the field in that table
    fieldname2 is the field in the table which (presumably) uniquely identifies the records in the table (e.g. the PK)
    formcontrol is a form field containing a value which identifies the record to be updated

    It also assumes that the text value to use for the update is the same each time. If not, i.e. you type in the new text, the SQL = ... statement will be a bit different.

  5. #5
    zero5587 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jan 2016
    Posts
    4
    thank you very much but what does this mean "fieldname2 is the field in the table which (presumably) uniquely identifies the records in the table (e.g. the PK)
    formcontrol is a form field containing a value which identifies the record to be updated"

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Use your actual field and control names in place of the dummy examples.

    You need some sort of filter parameter(s) to identify which record(s) in table to update. What information is on the form that can be used to identify records? If you want ALL records to have the same value then don't need filter parameter.

    But maybe 'put a text into a field' means you want to add NEW RECORDS?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    A SQL update statement will update all the records in the table, unless you use a WHERE clause to identify which specific record(s) you need to update.

    The table to be updated must have a field which can be used to identify the records (usually this will be the PK). So, when you click that update button, you need to have a value somewhere (a control value on your form) that you can use to identify which record is to be updated. Do you have such a control on your form?

  8. #8
    zero5587 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jan 2016
    Posts
    4
    So it is like you have 3 Buttons and a Table with 3 lines with different Names 1,2,3 if you put button 1 then put in line 1 yes. if you put button 2 then put in line 2 yes.

    sorry for my english

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    A table that has only 3 records? And will always have these 3 records?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Use a Command Button to make a new Table???
    By ajh2014 in forum Access
    Replies: 3
    Last Post: 10-14-2014, 08:05 AM
  2. Replies: 3
    Last Post: 05-02-2014, 09:02 AM
  3. Button that fills in a specific value
    By Renee R in forum Forms
    Replies: 2
    Last Post: 04-28-2014, 08:38 PM
  4. Replies: 1
    Last Post: 07-17-2013, 02:02 PM
  5. Replies: 3
    Last Post: 02-27-2013, 06:11 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