Results 1 to 7 of 7
  1. #1
    kieranharrison is offline True blue Aussie m8
    Windows 10 Access 2016
    Join Date
    Jun 2019
    Location
    Queensland, Australia
    Posts
    28

    Question Help writing code please!

    Hi Guys,



    Hoping one of the experts can help me with this ... it's a bit of a curly one (for me anyways)

    Basically, I am trying to make a form which has 4 fields on it that will populate the corresponding 4 fields in my received_files_table 'on click' using a command button. So the idea is to have the 4 fields in the form populated with data, then once the user selects on the command button the code runs and inputs the data into my received_files_table.

    I have been able to get the command button to work with only one field in the form which goes to my example table (shown below in green), however, I need to get it so that all 4 fields (shown below in red) input data into the received_files_table via only 1 command button.


    Click image for larger version. 

Name:	form_example_msaccess.png 
Views:	16 
Size:	46.4 KB 
ID:	38863




    I have managed to get the dummy data into the example table using the below code, however, I need help to write a code which works using all 4 fields in the form.


    Click image for larger version. 

Name:	code_example.png 
Views:	16 
Size:	33.1 KB 
ID:	38864



    As you can see the expression is - DoCmd.RunSQL "INSERT INTO example VALUES ([Combo26].Value)"

    The field names I need the new code to use are - Received_Date ; IATA_Code ; Processing_ Month ; Airline

    The corresponding table for these fields is called - received_files_table


    ​Thanks

  2. #2
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Why not just use a bound form?

    You should also declare Option Explicit at the top of every module. You can set it as the default in the VBE options. (check the box for "require variable declaration")

  3. #3
    kieranharrison is offline True blue Aussie m8
    Windows 10 Access 2016
    Join Date
    Jun 2019
    Location
    Queensland, Australia
    Posts
    28
    Hi moke123,

    Sorry I should've mentioned I am very new to access. Could you please explain how I could use a bound form?

    Thanks,

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,411
    Highlight the received_files_table in the navigation pane (like you show), then with the ribbon click Create, then click Form.
    This will crate a form bound to the table. The form will show ALL the fields in the table. Any changes made to the form data will be updated automatically to the table.

  5. #5
    kieranharrison is offline True blue Aussie m8
    Windows 10 Access 2016
    Join Date
    Jun 2019
    Location
    Queensland, Australia
    Posts
    28
    Thanks very much, davegri.

    then how do I get the command button to work and enter all of the fields?

  6. #6
    kieranharrison is offline True blue Aussie m8
    Windows 10 Access 2016
    Join Date
    Jun 2019
    Location
    Queensland, Australia
    Posts
    28
    Ahhh no worries, just realised you can use enter.

    Thanks for your help guys... i'll get there haha.

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,799
    realised you can use enter.
    Maybe not a good idea for you to depend on this. For bound forms, anything you do to commit record creation or edit will do the same. If you created a form with a single record view and the form has record navigation controls at the bottom, change a field in a record. Then navigate to another record, then go back to the one you edited but didn't press enter on. Change was kept?
    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. Problem writing code
    By JimO in forum Access
    Replies: 5
    Last Post: 02-13-2017, 07:23 PM
  2. Code writing
    By Obidombie in forum Forms
    Replies: 1
    Last Post: 02-11-2016, 04:11 AM
  3. Help Writing Date Change SQL Code
    By McArthurGDM in forum Programming
    Replies: 4
    Last Post: 06-30-2015, 01:36 PM
  4. help writing code that will update a table
    By 24t42 in forum Programming
    Replies: 1
    Last Post: 02-18-2015, 08:21 PM
  5. Writing code on the fly - TransferSpreadsheet
    By IanT in forum Import/Export Data
    Replies: 1
    Last Post: 05-24-2012, 08:28 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