Results 1 to 8 of 8
  1. #1
    Join Date
    Sep 2010
    Posts
    6

    Question lost - linking date field based on a record with smaller Unique ID

    I am totaly lost, here. I have a report with very difficult formatting. Main problem is that it has data for a week at a time, but it doesn't include the date of a record inside the actual record. I can import it to access, but once there, i can't sweem to match up records to dates. Data goes somewhat like this:

    Table Headers
    Record ID *** Date *** Field_1 *** Field_2 *** etc
    Actual Import Data:
    00000001 *** 01/01/2010 *** NULL *** NULL *** NULL
    00000002 *** NULL *** Name1 *** Plan1 *** Notes1
    00000003 *** NULL *** Name 2 *** Plan2 *** Notes2
    00000004 *** 01/02/2010 *** NULL *** NULL *** NULL
    00000005 *** NULL *** Name3 *** Plan3 *** Notes3
    00000006 *** NULL *** Name 4 *** Plan4 *** Notes4


    What i am trying to make my query do is to check if the date field is null, and if it is, to get a date from priv record with data in date field. So in this example, records 02 and 03 would have date from 01 (01/01/2010) and records 05 and 06 would get date from 04 (01/02/2010).

    I am guessing i need to make a subq to pull records with date fields (sort of like small headers through the report) and flag them as date fields. Then use some sort of logic to bounce rest of the records and finaly link them to the first records in a list (moving down... so if record id is 006, it would check 05 (null), then 04 (01/02/2010) and would put that date in a field.



    Any help? A link to a tutorial would be great... i really don't mind to do the leg work, just need to know what i am looking for.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Are you looking to update the data in the table, or just display it correctly in a query?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Join Date
    Sep 2010
    Posts
    6
    i'd like to change the data in the actual table... if needed though i am fine with just displaying it in a query and then making a "make table" query if needed.

    at this poing i'll take whatever i can ;0)

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Either is probably doable, I just wanted to head down the correct path. I'd open a recordset on the table, ordered by the ID field. As you loop through the recordset, put the date value into a variable. For each record, if the date value is null update it with the variable value, else change the variable to the current value.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Join Date
    Sep 2010
    Posts
    6
    i am fairly suck in VB... can you give me some pointers... do i need to create a new module? a new procedure? i assume i'll set a variable.

    but thanks for the help... i'll go ahead and start googling looping in vba.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The main tools you want are a loop and the Edit method of a recordset (of the two available, I'd use DAO). I use templates a lot, and this is my DAO loop template:
    Code:
      Dim strSQL  As String
      Dim db      As DAO.Database
      Dim rs      As DAO.Recordset
    
      Set db = CurrentDb()
      
      strSQL = "SELECT * FROM TableName ORDER BY FieldName"
      Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
    
      Do While Not rs.EOF
        'code here
        rs.MoveNext
      Loop
    
      set rs = nothing
      set db = nothing
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Join Date
    Sep 2010
    Posts
    6
    thanks man, this should be enough for me to get started...

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problemo; post back if you get stuck.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. File size smaller after saving
    By Pilotwings_64 in forum Access
    Replies: 1
    Last Post: 08-20-2010, 06:21 AM
  2. Set date field on subform to date variable
    By laavista in forum Access
    Replies: 4
    Last Post: 06-30-2010, 06:32 PM
  3. Total based on Formula based on field value
    By cjbuechler in forum Reports
    Replies: 15
    Last Post: 07-10-2009, 09:56 AM
  4. Select a certain field of a record based on ID
    By cesarone82 in forum Access
    Replies: 3
    Last Post: 06-06-2009, 01:16 PM
  5. Unique Record Identifier for MS SQL Server Tables
    By MGSP in forum Import/Export Data
    Replies: 2
    Last Post: 01-29-2006, 03:00 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