Results 1 to 9 of 9
  1. #1
    cbende2's Avatar
    cbende2 is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jun 2014
    Location
    Louisiana
    Posts
    370

    Question Incrementing textbox to assign value

    Hello all,

    I have 52 unbound text boxes on a form.

    I'm trying to create a For loop that will assign each textbox a value, here's my code:



    Code:
    Private Sub Form_Load()
    
    Dim O(6, 52) As Integer
    Dim i As Integer
    
    For i = 0 To 51
    
        O(1, i + 1) = DCount("Field1", "Table1", "DateValue([Field1]) Between DateSerial(Year(Date())-1,1,1) And DateSerial(Year(Date())-1,1,8)")
        Me.Text(i + 1).Value = O(1, i + 1)
        
    Next i
    
    End Sub
    After I get this figured out, I'll be trying to figure out how I can increment the DateSerial by the 52 weeks of the year.

    So basically each textbox(1-52) will have a count for each week of the year.

    Hopefully this makes since, but that is for a future post, right now I'm just trying to figure out if I can increment a textbox to give it a value.


    Thank you!

  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,444
    assuming your controls are called text1, text2 etc then try this

    Code:
    For i = 0 To 51
    
        Me("Text" & i+1) =  DCount("Field1", "Table1", "DateValue([Field1]) Between DateSerial(Year(Date())-1,1,1) And DateSerial(Year(Date())-1,1,8)")
        
    Next i
    I have no idea what the dcount is supposed to do - looks like it will fill all your boxes with the same value between Jan 1st and Jan 8th of last year

  3. #3
    cbende2's Avatar
    cbende2 is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jun 2014
    Location
    Louisiana
    Posts
    370
    Yep, that worked. Thanks Ajax,

    And I have text1-text52.

    I'm trying to figure out a way to increment the weeks now. So each textbox is assigned 1 week of the year.

  4. #4
    cbende2's Avatar
    cbende2 is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jun 2014
    Location
    Louisiana
    Posts
    370
    So text1 will be Jan1-Jan8
    text2 will be Jan8-Jan15
    text3 will be jan15-Jan21
    and so on...

  5. #5
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,444
    with regards your 'count by week', be aware there can be 53 weeks in the year.

  6. #6
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,444
    So text1 will be Jan1-Jan8
    text2 will be Jan8-Jan15
    text3 will be jan15-Jan21
    Are you sure - so you want to add values on Jan8 to both week 1 and week 2?

  7. #7
    cbende2's Avatar
    cbende2 is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jun 2014
    Location
    Louisiana
    Posts
    370
    Quote Originally Posted by Ajax View Post
    Are you sure - so you want to add values on Jan8 to both week 1 and week 2?
    I guess not, but you get what I'm saying

  8. #8
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,444
    an imprecise answer gets an imprecise suggestion. Look at using the dateadd function to determine the two between dates. I question you needing the datevalue function if field1 is a datetime field. You can also look at the format function to determine a week number

    good luck with your project

  9. #9
    cbende2's Avatar
    cbende2 is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jun 2014
    Location
    Louisiana
    Posts
    370
    My field is a Short text field.

    I'll see what i can do.

    Thanks Ajax

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

Similar Threads

  1. assign value to textbox from different tables
    By joe55555 in forum Access
    Replies: 1
    Last Post: 02-11-2015, 04:55 AM
  2. Incrementing a textbox on a continuous form
    By ultimateguy in forum Access
    Replies: 6
    Last Post: 08-19-2014, 06:38 AM
  3. Replies: 5
    Last Post: 04-16-2013, 07:24 PM
  4. Help with incrementing a counter
    By Ben M in forum Database Design
    Replies: 4
    Last Post: 05-22-2012, 06:46 AM
  5. Incrementing Numbers
    By anastazia1117 in forum Access
    Replies: 3
    Last Post: 07-13-2011, 03:44 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