Results 1 to 5 of 5
  1. #1
    oldlearner is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Sep 2015
    Posts
    31

    After event macro to update another table using a drop down list field as criteria

    Hi There. I Am new to access database design (teaching myself from a book) and am wondering if anyone can help please. I have a table with a dropdown list field. I want to update some fields (create a record) into another table, but only if they match the criteria for the item I have selected from that list. example: table1 has Id, FirstName, Surname and programme fields (the programme field is a drop down values list ie: programme1, programme2, programme3 etc.. Table2 has FirstName, Surname fields along with other fields. I want to drop FirstName and Surname from table 1 into table 2 using an after event macro but only the names from people who have been selected as programme2 from the drop down values list.



    Any ideas or am I going about this the wrong way.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Use VBA, not macro.

    If Me.comboboxname.Column(x) = "programme2" Then
    CurrentDb.Execute "INSERT INTO table2(FirstName, Surname) Values('" & Me.comboboxname.Column(x) & "', '" & Me.comboboxname.Column(x) & "')"
    End If

    The x is reference to combobox column index. Index begins with 0.

    Why are you saving name parts instead of ID? Should not duplicate name into multiple tables. Names make poor unique identifiers.
    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.

  3. #3
    oldlearner is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Sep 2015
    Posts
    31
    Thanks for the info moderator. I am not familiar with VBA yet (haven't read that bit of the book yet). I seem to have managed to get a macro to work as I want using the IF Then Else and set field instructions incorporating the expression builder. As you rightly say I needed to and have used the ID field as a unique identifier.

    Thanks again

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    So this is resolved? Or you need more info about VBA?

    Macro will not be able to run the dynamic INSERT sql action. Macro can open and run query objects but query cannot reference combobox column index. However, if you save the ID instead of name parts, and the value of the combobox is the ID field, then a query can reference the combobox and a macro could run the query.
    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.

  5. #5
    oldlearner is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Sep 2015
    Posts
    31
    Thanks June
    Used a combo box as suggested and is acting as required now.

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

Similar Threads

  1. Replies: 2
    Last Post: 08-27-2015, 07:38 AM
  2. Replies: 0
    Last Post: 11-30-2014, 03:12 AM
  3. Replies: 2
    Last Post: 04-13-2014, 06:55 PM
  4. Replies: 3
    Last Post: 03-10-2012, 06:15 PM
  5. Update Field list in Table with Query
    By Scorpio11 in forum Queries
    Replies: 3
    Last Post: 07-16-2010, 01:57 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