Results 1 to 2 of 2
  1. #1
    TonyB is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    Oxfordshire, UK
    Posts
    16

    looping through records until matching criteria is found, then filling in a record


    Hi,

    Not very pro with VBA - been struggling with this for hours!
    Here's the code that works so far, and is triggered on form load. It works, but only if it can find a PI, and they are the first entry in the recordset:

    Code:
    If Forms!frmProject!frmSubPerProj.Form.RolePerProj = "Principal Investigator" Then
            Me.Principal_Investigator = Forms!frmProject!frmSubPerProj.Controls("fullname")
    End If
    To give you a better understanding of what's going on:
    Firstly, I have a form open called "frmProject" which has a field called "Principal_Investigator". There is a sub-form called "frmSubPerProj" which holds the records of people associated with a project; including their names and their role within the project.

    What I want to do is every time the form is opened, the "Principal Investigator" field on "frmProject" needs to be filled with the name of the Principal Investigator found in the subform ("RolePerProj" is the field in the subform that denotes the PI). If no principal investigator exits, then leave the field blank.

    I think I need to use some looping system here, so that if the first record returns a "RolePerProj" value of false, then check the next records until Access finds the first "RolePerProj" value as being "Principal Investigator". I've tried various things I've found on the internet, but none seem to work for me.

    Thanks

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Perhaps the solution is to use the form's On Current event. The On Load event only fires at the time the form is Opened/Loaded.

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

Similar Threads

  1. do Loops - Not looping thru all records
    By kfschaefer1 in forum Programming
    Replies: 1
    Last Post: 03-27-2014, 11:42 PM
  2. Selecting records with matching criteria
    By Daryl2106 in forum Access
    Replies: 2
    Last Post: 09-07-2013, 03:57 AM
  3. Replies: 1
    Last Post: 10-24-2011, 08:01 AM
  4. Replies: 1
    Last Post: 08-11-2011, 11:33 AM
  5. Looping through Records in SQL
    By make me rain in forum Queries
    Replies: 13
    Last Post: 07-17-2011, 08:58 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