Results 1 to 6 of 6
  1. #1
    darwin is offline Novice
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    28

    How to make a loop in VB

    I am new in Access not much experiance with VB

    I have a LoopForm.accdb

    Inside the LoopForm.accdb database I have a table DateTable


    The DateTable has the columns: ID, DateToday, StartDate, EndDate

    I have a DateTableForm with the elements DateTodayForm, StartDateForm and EndDateForm.

    What I want is when the DateTableForm is opened up, the dates for all three boxes
    is automatically filled with dates.


    Then the loop

    The DateTodayForm = currentdate

    StartDateForm = begin start at April 27

    EndDateForm = begin end at May 10

    if currentdate is between April 27 and May 10

    Then StartDateForm = April 27

    and EndDateForm = May 10



    if not

    the loop should spell 2 weeks up

    if

    currentdate is between May 11 and May 24

    Then StartDateForm = May 11

    and EndDateForm = May 24

    and so on



    Any one WHO can tell about how I do this in a Modules with VB ??

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Why using VBA?

    Why don't you bind the form to the table then bind textboxes to fields. Data will automatically display. No code required.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    darwin is offline Novice
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    28
    thanks

    But thats logic

    But I am in the learning mode about vba, and could use it in other solutions.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Some developers do use unbound forms/controls to display data from tables - I never have.

    If you want to display data from all records, better use bound form. If you want to pull data for only one record - which one? How do you want to identify which record?

    I should think there are more practical exercises for learning VBA. Here's one that demonstrates opening a recordset and looping through the records and outputting data to the VBA immediate window:

    Sub TestVBALoop()
    Dim rs AS DAO.Recordset
    Set rs = CurrentDb.OpenRecordset ("SELECT * FROM DateTable")
    While Not rs.EOF
    Debug.Print rs!DateToday & " : " & rs!StartDate & " : " & rs!EndDate
    rs.MoveNext
    Wend
    End Sub

    If you just want to set textboxes with values that have no connection to data in table, a loop is not needed. But you are describing conditional code.
    Me.DateTodayForm = Date()
    If Date() >= "4/27/" & Year(Date()) And Date() <= "5/10/" & Year(Date()) Then
    Me.StartDateForm = "4/27/" & Year(Date())
    Me.EndDateForm = "5/10/" & Year(Date())
    Else
    ...
    End If
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    darwin is offline Novice
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    28
    thanks jun7

    But my criteria is

    April 27 - May 10
    May 11 - May 24
    May 25 - June 7
    June 8 - june 21
    and so on in the endless with + 14 days

    so the currentday is crucial for the start day and end day

    The idea is that the user do not have to even have to sign these days

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Sorry, I don't understand the purpose. Take my example of If Then and adapt as needed.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 4
    Last Post: 02-06-2015, 03:58 AM
  2. Replies: 13
    Last Post: 08-20-2014, 09:17 AM
  3. Replies: 17
    Last Post: 04-07-2014, 07:48 PM
  4. Replies: 3
    Last Post: 03-10-2013, 07:04 AM
  5. Loop through Records and Make ID
    By rob4465 in forum Programming
    Replies: 3
    Last Post: 01-14-2010, 10:46 AM

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