Results 1 to 11 of 11
  1. #1
    rdscott is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    9

    update field in existing records displayed in subform from main form autonumber

    I have a two tables: school (one) and members (many) linked together by schoolID. There is a yes/no field (newmembers) in members to identify new members.



    I have a form to create an invoice for a particular school (by selecting school from combobox) which creates an autonumber invoiceID. There is a subform to display the new members linked to that school and if newmembers is true. This displays automatically.

    I want to automatically update a field (invno) in the members table as it is being displayed in the subform from the autonumber invoiceID from the main form.

    Can this be done?

    Thanks

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,943
    I expect there is but does this mean each member will be included on only one invoice?
    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
    rdscott is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    9
    as new members are added to the school there is a one time charge for membership. those members need to link to the invoice they were billed on.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,943
    Try an UPDATE sql action. Since they will no longer be NewMember need to also set that field to False. In VBA code, like:

    CurrentDb.Execute "UPDATE Members SET InvNo='" & Me.InvNo & "', NewMember=False WHERE SchoolID='" & Me.SchoolID & "' AND NewMember=True;"

    If InvNo and SchoolID are number datatype, remove the apostrophe delimiters.

    However, better commit the invoice record to table before running the update.
    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
    rdscott is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    9
    Thanks for your help but I can't seem to get it to work.

    InvNo and SchooliD are numeric. How would i make the SQL action automatically after autonumber has been populated?

    Thanks,

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,943
    I don't know if can attach code to a textbox bound to autonumber field. Never tried. Could try in the AfterUpdate event of form but I've never done that either.

    Why doesn't it work - error message, wrong results, nothing happens? Where did you put the code?
    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
    rdscott is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    9
    nothing happens... i added to autonumber field as an afterupdate event.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,943
    Then there is the form Close or AfterUpdate events or a button Click event.
    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.

  9. #9
    rdscott is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    9
    got it to work. thanks for your help.

    put the following code in afterupdate on first field in form. would not work without the refreshrecord

    DoCmd.RefreshRecord
    CurrentDb.Execute "UPDATE tblMembers SET InvoiceNo=" & Me.Invoice & " WHERE CollegeID=" & Me.CollegeID & " AND NewMember=True;"

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,943
    Don't need to change True to False?
    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.

  11. #11
    rdscott is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    9
    yes, I took that temporarily for testing purposes. forgot to post updated code.

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

Similar Threads

  1. Requery subform after update of main form
    By gemadan96 in forum Forms
    Replies: 3
    Last Post: 10-17-2012, 02:33 PM
  2. Replies: 1
    Last Post: 07-20-2012, 09:48 AM
  3. Replies: 11
    Last Post: 10-20-2011, 08:41 AM
  4. Update field in subform from field in Main
    By jpkeller55 in forum Access
    Replies: 9
    Last Post: 10-15-2010, 03:37 PM
  5. Replies: 1
    Last Post: 10-13-2010, 12:40 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