Results 1 to 3 of 3
  1. #1
    Ashe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2010
    Location
    Blacksburg VA
    Posts
    65

    Quick coding-orginization question

    I'm just learning coding in Access and I had to write this code (below) for a form, but I'm sure this is not truly the best or most concise way to write this...How could I have written this more simply? I know there's got to be a better way...




    Code:
    Sub TrackingRequery()
        Me.cboYear1.Requery
        Me.cboYear2.Requery
        Me.cboYear3.Requery
        Me.cboYear4.Requery
        Me.cboYear5.Requery
        
        Me.cboYear1.Value = Null
        Me.cboYear2.Value = Null
        Me.cboYear3.Value = Null
        Me.cboYear4.Value = Null
        Me.cboYear5.Value = Null
        
        Me.cboYear1Percent.Requery
        Me.cboYear2Percent.Requery
        Me.cboYear3Percent.Requery
        Me.cboYear4Percent.Requery
        Me.cboYear5Percent.Requery
        
        Me.cboYear1Percent.Value = Null
        Me.cboYear2Percent.Value = Null
        Me.cboYear3Percent.Value = Null
        Me.cboYear4Percent.Value = Null
        Me.cboYear5Percent.Value = Null
    End Sub
    Thanks in advance for helping me on this silly question...

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Because names are similar could use loop and controls class:

    Dim i As Integer
    For i = 1 to 5
    Me.Controls("cboYear" & i).Requery
    Me.Controls("cboYear" & i).Value = Null
    Me.Controls("cboYear" & i & "Percent").Requery
    Me.Controls("cboYear" & i & "Percent").Value = Null
    Next
    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
    Ashe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2010
    Location
    Blacksburg VA
    Posts
    65
    Thank you!

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

Similar Threads

  1. Quick SQL Query question.
    By Suoipoc in forum Access
    Replies: 4
    Last Post: 09-06-2011, 09:10 PM
  2. Quick question for all of those who use Access
    By claytonkeirns in forum Access
    Replies: 1
    Last Post: 09-06-2011, 04:04 PM
  3. Coding question
    By kzoli62 in forum Access
    Replies: 1
    Last Post: 07-04-2011, 05:09 PM
  4. Quick Module Question: :)
    By oregoncrete in forum Modules
    Replies: 11
    Last Post: 04-04-2011, 04:42 PM
  5. Quick Question
    By Imgsolutions in forum Access
    Replies: 3
    Last Post: 07-19-2010, 11:22 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