Results 1 to 7 of 7
  1. #1
    cam2era is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2011
    Posts
    9

    Copying from non-null field in table to the next records below.

    Hello,

    Our lab manager has given me an excel file with lab tests grouped by patient code. I've imported this into Access 2010.



    However, the records for the labs do not repeat the patient code in each line. I've tried to create a macro that will use the "sendKeys" command to copy, then paste, the patient code in the field (field #1) for each record (stopping when reaching the next patient code).

    It seems like this should be very doable, but I've been unsuccessful. There are many hundreds of labs (about 7 per patient), so I need to automate this. Thanks much.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Will this idea work for you: http://www.mvps.org/access/forms/frm0012.htm

  3. #3
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    cam,

    what's your data look like?? anything like the following??


    PATIENT CODE LAB NUMBER
    Code:
    PATIENT CODE	LAB NUMBER
    1	4
    	5
    	6
    	7
    	8
    	89
    	0
    	8
    	76
    	5
    	4
    2	4
    	56
    	78
    	8
    	3
    	2
    	2
    	2
    	34
    	5
    3	5
    	4
    	5
    	7
    	8
    	88

    if it does look like that, put this function in access and run it:

    Code:
    function fillThoseMissingNums()
    
    dim rs as dao.recordset
    dim phold as long
    
    set rs = currentdb.openrecordset("table name", dbopendynaset)
    
    with rs
       .movelast
       .movefirst
    
       phold = ![Patient Code FieldName]
    
       .movenext
    
          do until .eof
    
             if isnull(![Patient Code FieldName]) then
                .edit
                   ![Patient Code FieldName] = phold
                .update
             else
                if ![Patient Code FieldName] <> phold then
                   phold = ![Patient Code FieldName]
                end if
             end if
    
       .movenext
          loop
    
    end with
    
    rs.close
    
    set rs = nothing
    
    end function

  4. #4
    cam2era is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2011
    Posts
    9
    Adam,

    Yes, that's just how our lab table looks.

    My experience with programming is a bit rudimentary. How would I set up the function? Would I put it in a window in the VBA editor? I'm pretty used to making buttons on forms that will invoke code in the editor (and macros), but no much beyond.

    Thanks so much for your help!

    Ernie (cam2era)

  5. #5
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    GO TO THE VB EDITOR, insert a new module and paste the code in

  6. #6
    cam2era is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2011
    Posts
    9

    A great solution

    Got it! It works great. Very elegant & it makes short work of making a very long list usable. Thanks again...

  7. #7
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    marked solved

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

Similar Threads

  1. Replies: 5
    Last Post: 03-23-2011, 10:39 AM
  2. Replies: 3
    Last Post: 01-15-2011, 02:39 AM
  3. Replies: 0
    Last Post: 07-16-2010, 09:06 AM
  4. Copying only part of data from a text field
    By davedejonge in forum Queries
    Replies: 1
    Last Post: 02-03-2010, 05:18 PM
  5. Replies: 2
    Last Post: 01-22-2010, 03:53 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