Results 1 to 7 of 7
  1. #1
    dvgef2 is offline Novice
    Windows 8 Access 2013
    Join Date
    Mar 2013
    Posts
    25

    Loop or Array not recognized

    I feel so dumb because there has to be a better way of doing this. I am trying to prevent a field from being filled out if it is being done out of order. Access does not seem to recognize the fields when I use it in an array or loop....I must be doing something wrong with the syntax but the following code is the only thing that I can get to work.



    If [curAmount1] <= 0 Or [curAmount2] <= 0 Or [curAmount3] <= 0 Or [curAmount4] <= 0 Or [curAmount5] <= 0 Or [curAmount6] <= 0 Or [curAmount7] <= 0 Or [curAmount8] <= 0 Or [curAmount9] <= 0 Or [curAmount10] <= 0 Or [curAmount11] <= 0 Then
    MsgBox "Please fill the payment blocks in the proper order as displayed", 0, "ERROR, ERROR, ERROR!!!!"
    [curAmount12PD] = 0
    [dteDate12PD] = Null
    [curAmt12] = Null
    End If

    If anyone has any suggestions it would be helpful.

    Dave

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Hard to fix what you don't show, but presuming those are controls, in a loop:

    Me("curAmount" & VariableName)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Think need to use Controls collection when constructing control name with variable:

    For i = 1 to 11
    If Me.Controls("curAmount" & i) <=0 Then
    'do something
    End If
    Next

    Is the form in Single view? Another approach is to make the controls available only when appropriate. Set all but the first one as Enabled No then in the BeforeUpdate event of each control make the next Enabled Yes, example:

    Sub curAmount1_BeforeUpdate(Cancel As Integer)
    Me.curAmount2.Enabled = True
    End Sub
    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.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    If that was directed at me, no Controls collection needed. What I posted works.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Nice! Don't know what I originally tried (several years ago) that led me to think Controls collection was needed. Will have to take another look at that old code.
    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.

  6. #6
    dvgef2 is offline Novice
    Windows 8 Access 2013
    Join Date
    Mar 2013
    Posts
    25
    Thanks so much Phil and June7! I apologize for not putting more information but I was so frustrated because even though I don't use code a lot or know a lot about it, I knew there was an easier way of doing this than what I had. I literally spent more than 10 hours each day during the Memorial Day Weekend and many hours since then researching other code examples and trying different combinations of brackets and quotations to make this work but it would either do it wrong or give me errors. It beat me and so I decided to ask for help and I really appreciate the quick responses you both gave. Interesting thought about just disabling and enabling the controls. I really should take a course! I spend more time experimenting with harder ways of doing things and you guys come up with the easy solutions as if it was second nature. Thanks again!

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    No problem Dave!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 03-10-2013, 07:04 AM
  2. Replies: 30
    Last Post: 08-30-2012, 05:14 PM
  3. Replies: 5
    Last Post: 08-23-2012, 09:33 AM
  4. can i put the result in array?
    By dada in forum Programming
    Replies: 1
    Last Post: 08-19-2010, 07:17 PM
  5. New Record not recognized in my queries
    By Kimmcdt in forum Queries
    Replies: 6
    Last Post: 01-16-2010, 10:26 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