Hi For Loop Problems:

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • darrel
    New Member
    • Nov 2006
    • 72

    #1

    Hi For Loop Problems:

    Hi there can somebody tell how can will i be able to shorten my code: coz i think the code that i have is very redundant, can someone help me with this, i just want to do it in a single for loop.

    Here's my code:

    Code:
    'Time Connection
    If rs.State = adStateOpen Then rs.Close
           rs.Open "Select * from [Time]", cnn, adOpenKeyset, adLockOptimistic
        While rs.EOF <> True
            For x = 0 To 11
             frmMain.Combo1(x).AddItem rs.Fields("Time").Value
            Next x
         rs.MoveNext
        Wend
    'Time Connection
    
    'Room Connection
    If rs.State = adStateOpen Then rs.Close
           rs.Open "Select * from [ROOMS]", cnn, adOpenKeyset, adLockOptimistic
      While rs.EOF <> True
        For x = 0 To 11
             frmMain.Combo2(x).AddItem rs.Fields("ROOM").Value
        Next x
      rs.MoveNext
      Wend
    'Room Connection
    
    'Days Connection
    If rs.State = adStateOpen Then rs.Close
           rs.Open "Select * from [DAYS]", cnn, adOpenKeyset, adLockOptimistic
      While rs.EOF <> True
        For x = 0 To 11
             Form2.Combo3(x).AddItem rs.Fields("DAYS").Value
        Next x
      rs.MoveNext
      Wend
    'Days Connection
    i hope someone hav an idea on this, thank you in advance.
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Originally posted by darrel
    Hi there can somebody tell how can will i be able to shorten my code: coz i think the code that i have is very redundant, can someone help me with this, i just want to do it in a single for loop.

    Here's my code:

    Code:
    'Time Connection
    If rs.State = adStateOpen Then rs.Close
           rs.Open "Select * from [Time]", cnn, adOpenKeyset, adLockOptimistic
        While rs.EOF <> True
            For x = 0 To 11
             frmMain.Combo1(x).AddItem rs.Fields("Time").Value
            Next x
         rs.MoveNext
        Wend
    'Time Connection
    
    'Room Connection
    If rs.State = adStateOpen Then rs.Close
           rs.Open "Select * from [ROOMS]", cnn, adOpenKeyset, adLockOptimistic
      While rs.EOF <> True
        For x = 0 To 11
             frmMain.Combo2(x).AddItem rs.Fields("ROOM").Value
        Next x
      rs.MoveNext
      Wend
    'Room Connection
    
    'Days Connection
    If rs.State = adStateOpen Then rs.Close
           rs.Open "Select * from [DAYS]", cnn, adOpenKeyset, adLockOptimistic
      While rs.EOF <> True
        For x = 0 To 11
             Form2.Combo3(x).AddItem rs.Fields("DAYS").Value
        Next x
      rs.MoveNext
      Wend
    'Days Connection
    i hope someone hav an idea on this, thank you in advance.
    Hey, darrel!

    Is it necessary to have Combo3 on a different form, why not a frame within the same form. That should help reduce the code....

    Comment

    Working...