Consulting

Results 1 to 10 of 10

Thread: Solved: Assign a value in a recordset

  1. #1
    VBAX Regular
    Joined
    May 2004
    Posts
    42
    Location

    Solved: Assign a value in a recordset

    Is there a way to count through a recordset and assign a value to the amount of records that you want? I would like to have a form that I enter a number, let us say 24 as an example (This number will change for each recordset). Then I would like to open an update query (or anything else) and assign a period value of ?Period 1? to the first 24 records (That is what I entered in the form). The next 24 records I would like to enter ?Period 2? and so on until I complete ?Period 8?.

    Real world situation
    There is a list of list of things to be accomplished which is represented by the recordset that is in the order it is to be done in. The individual is capable of doing 24 of them in an hour. I would like to see at which point each individual will be at, or should be at, at each period.

  2. #2
    VBAX Regular GP George's Avatar
    Joined
    Jul 2004
    Location
    Puget Sound, WA
    Posts
    26
    Location
    Yes, you can do this with either ADO or DAO recordsets. Here's a DAO example.

    Public Function fMarkItems(intStartItemCount as Integer, intEndItemCount as Integer)
    Dim rs As DAO.Recordset
    Dim I as Integer

    Set rs = CurrentDb.OpenRecordset("tblYourTable")
    With rs
    For I = intStartItemCount to intEndItemCount
    .Edit
    !FieldtoUpDate = "Period 1"
    .Update
    .MoveNext
    Next I
    End With
    End Function

    =====

    This code will update one field in the table, starting with the record you specify in the argument intStarttemCount and ending with the record you specify in the argument intEndItemCount.

    HTH

    George
    "We're all in this together."
    -Red Green

  3. #3
    VBAX Regular
    Joined
    May 2004
    Posts
    42
    Location
    I do not know if you have the time to do this or not but I am not sure how to do this. I take the code that you gave me and I create a module for it. How do I add the starting number and ending number? How do I call it from the form that I am placing the numbers in?

  4. #4
    VBAX Regular
    Joined
    May 2004
    Posts
    42
    Location
    I was actually able to get this to somewhat work. I figured out what I asked you in my last reply but I have a different problem now.

    It looks like the difference from the first number to the second number is the count of the records that gets updated from the first record. Let me see if I can say this better.

    If I enter in 1 in the first field and 20 in the second it updates the 1st through the 20th records. If I put in 21 and 60 it updates the first 40 records. So it looks like it is not updating based on the position but calculating the difference and updating that number of records from the beginning. Is that what it is supposedd to be doing?

    I appreciate your help, thank you.

  5. #5
    VBAX Regular GP George's Avatar
    Joined
    Jul 2004
    Location
    Puget Sound, WA
    Posts
    26
    Location
    You're right that the code I posted doesn't handle the second and subsequent groups of records correctly. It always STARTS with the first record.

    Let me think about an alternative.

    George
    "We're all in this together."
    -Red Green

  6. #6
    VBAX Regular GP George's Avatar
    Joined
    Jul 2004
    Location
    Puget Sound, WA
    Posts
    26
    Location
    Which Version of Access are you using?
    "We're all in this together."
    -Red Green

  7. #7
    VBAX Regular
    Joined
    May 2004
    Posts
    42
    Location
    I am using Access 2000. Thanks.

  8. #8
    VBAX Regular GP George's Avatar
    Joined
    Jul 2004
    Location
    Puget Sound, WA
    Posts
    26
    Location
    I'm thinking about a solution which involves checking whether there is already a value in this field and only updating records where there is no value. In other words, once you've marked a group of records with, say "Period 1", those records would be ignored for the next set of marks. Would that work?

    George
    "We're all in this together."
    -Red Green

  9. #9
    VBAX Regular GP George's Avatar
    Joined
    Jul 2004
    Location
    Puget Sound, WA
    Posts
    26
    Location
    Check the demo in the attached db.
    "We're all in this together."
    -Red Green

  10. #10
    VBAX Regular
    Joined
    May 2004
    Posts
    42
    Location
    That's exactly it. Thank you very much for your help and the valuable lesson.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •