Results 1 to 12 of 12
  1. #1
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544

    Question Find field value Horizontally

    I am comfortable finding a column's value moving vertically. How can you return a field value moving horizontally? I am checking each field for a sepcific record. The fields contain dates in weekly increments. I am passing a date to the function and want to check that date against each date field for that record.



    i.e....
    Pass emplID, emplDate to funVerify

    For the record containing emplID I need to compare emplDate to the 10 dates in the row.

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    use a "for each" loop with a field object variable declared or incrementing integer loop (for x = low to high)

  3. #3
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Ok, let me add a little twist....

    For each date field their is a corresponding Yes/No field. When I identify the correct week field I need to flag the corresponding Yes/No field to a "Yes". Is there a way to return the column name? I know how to look up a specific column, but not the other way around.

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    what do you mean "the other way around"? I don't know the opposite of column name.

    you have to figure out if there is any patternization to this. That's the backbone of programming anyway. That's how programs are written.

    so if your structure is something like:
    Code:
    date1 yes/no1 date2 yes/no2
    then all you have to do is issue the flag on the next loop. On the current loop, if the date matches, set an indicator and keep on checking that indicator on the subsequent loops.

    could you do that i suppose?

  5. #5
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Ok....Yes I have it set up in a pattern.....Week1, Exempt1, Week2, Exempt2, etc...

    In regards to the "other way around" I know you can use rs("ColumnName") to return the value of the column. I'm just looking for a way to return the column name.

    So I have the below code set up. What you are saying is this will act the same way a "While" loop works? So I could put a counter in there?
    Code:
    For Each varField In rs.Fields
        'Check to see if week date = trans_date
        i = i + 1
        'Update value to "Yes"
    Next varField

  6. #6
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Code:
    For Each varField In rs.Fields
        'Check to see if week date = trans_date
        i = i + 1
        'Update value to "Yes"
    Next varField
    works fine it ''varfield'' is dimmed like so:
    Code:
    dim varfield as dao.field
    vba understands that. you're asking for each object in that same collection of objects, so it complies with you.

    to get a column name, use the property. almost all objects have it:
    Code:
    rs("column").name
    usually, people use the long reference though:
    Code:
    rs.fields("column").name

  7. #7
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Why use rs.fields("column").name vs. rs("column").name? Is it strictly preferential?

    I currently have varField dimmed as a field

    Code:
    Dim varField as Field
    Will that work or is it absolutely necessary to dim it as dao.field? Just curious.

  8. #8
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    One more question...

    I am passing a record identified to the function so I only want to perform the "for each" "loop" (for lack of a better term). How do I tell the recordset to only look through the fields for that one record as opposed to all records in the table?

    Here is my code for the filter, but the filter does not work. I tried setting the rs back to itself again because I read you had to do that. I have tried without setting it back to itself and it still doesn't work.

    Code:
    Function funUpdateWeeks(emplID As Long, emplDate As Date)
    Dim varField As Field
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim rs1 As DAO.Recordset
    Dim i As Integer
    Dim varWeekVal, varExemptVal
    Set db = CurrentDb
    Set rs = db.OpenRecordset("tblExempt", dbOpenDynaset)
    Set rs1 = db.OpenRecordset("SLAUDIT_FDT_SA_EXCP_SUMM_DIST", dbOpenDynaset)
    'rs.FindFirst "[EmplID] = " & emplID
    rs.Filter = "[EmplID] = " & emplID
    Set rs = db.OpenRecordset("tblExempt", dbOpenDynaset)
    i = -2
    For Each varField In rs.Fields
        'Check to see if week date = trans_date
        i = i + 1
        If i > 0 Then
            varWeekVal = rs("Week" & i)
            If DatePart("ww", varWeekVal) = DatePart("ww", emplDate) Then
                If DatePart("yyyy", varWeekVal) = DatePart("yyyy", emplDate) Then
                    rs.Edit
                    rs("Exempt" & i).Value = -1
                    rs.Update
                End If
            End If
        End If
    Next varField
    rs.Close
    rs1.Close
    End Function

  9. #9
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by jgelpi16 View Post
    One more question...

    I am passing a record identified to the function so I only want to perform the "for each" "loop" (for lack of a better term). How do I tell the recordset to only look through the fields for that one record as opposed to all records in the table?
    do you know what a pointer is? recordsets use this same thing. you work in one record ONLY, until you tell the pointer to move. e.g. -
    Code:
    rs.movelast
    moves the pointer to the last record of the set you opened. then, you are working strictly on the record, basically with whatever you do, until you move again.

    I worked in a call center a long time ago, and it was an ongoing joke about the Java pointer because everyday we saw the 'null pointer exception' error on at least 5 screens. it was a funny, but sad indication of how poorly the software was written way back in the day.

    as far as dimming, vba doesn't require declarations. But you'd never know it, because virtually all professionals do it anyway. so no, but to my knowledge you cannot suppress a declaration and attempt to that variable in a loop. for instance, this will not work without an explicit dec:
    Code:
    for each fld in rs.fields
    I believe it throws a 'type not defined' or something. That has never worked for me.

    I don't like dec'ing variables because it takes so much time to do. I used to, but not anymore. But if you're not an expert in this language, I would recommend always doing it, so you don't confuse yourself in your own programs later on!

  10. #10
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    agetrumpet I really appreciate you taking the time to explain all of this. I really enjoy learning 10 times more than I enjoy someone giving me the code....Although somtimes that's nice too . I certainly have come to understand recordset a lot better. Thanks again.

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

    And for the record...giving code out promotes laziness. Sorry, but I don't belong to that organization (would that be the government of the USA??).

  12. #12
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    LOL! I don't know how you could hint at such a thing.

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

Similar Threads

  1. Find specific value in any field
    By bkvisler in forum Queries
    Replies: 8
    Last Post: 12-08-2010, 04:23 PM
  2. Find Maximum Value of a Field and Add 1
    By jhillbrown in forum Forms
    Replies: 3
    Last Post: 03-11-2010, 11:42 AM
  3. Expand field horizontally
    By jonsuns7 in forum Reports
    Replies: 1
    Last Post: 10-15-2009, 04:54 AM
  4. Find Spaces in Field
    By stottle in forum Queries
    Replies: 6
    Last Post: 08-17-2009, 02:02 AM
  5. query to find the highest value in a field
    By jhjarvie in forum Queries
    Replies: 0
    Last Post: 09-02-2008, 02:27 PM

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