Results 1 to 9 of 9
  1. #1
    khumbo is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Posts
    12

    looping through controls on a form


    Hey guys, i've been googling for hours on this but can't seem to find anything.

    I'm trying to loop through all the textboxes on a form and if the textbox is empty then change the back colour to red. I've found several pieces of code that can help me with this but i think here is where the problem lies: when i declare the control, its starts off as 'Dim Ctrl as Control' and soon as i go to the next line, 'Control' goes down to a lower case 'control' and as a result i cannot use several of its properties such as .Value. Anybody know what's going on and how i can fix it? Much appreciated!

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    This behavior, changing the 'C' to lower-case, would indicate that you have a Control, somewhere, named control (spelled with a lower-case 'c') and this is confusing the Access Gnomes! Use 'Find' to figure out where it is and change the name to something else.

    Linq ;0)>

  3. #3
    khumbo is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Posts
    12
    thanks a bunch, will give this a shot and let you know

  4. #4
    khumbo is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Posts
    12
    tried searching through all the controls but couldn't find any with a name that includes 'control'. Any other ideas?

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Would Conditional Formatting serve for this situation?

    Are you doing this with form in Continuous or Datasheet view?
    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
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Sure:

    1. Expression Is
    2. IsNull([ControlName])
    3. Format the BackColor as desired

    Sadly, while some things, in Conditional Formatting, can be done for multiple Controls, in one fell swoop, this is not one of them; it has to be done separately for each Control.

    Of course, if the OP were to be a bad boy (is that sexist?) he could not use Option Explicit, for the Form, and wouldn't have to Dim the Variable; the looping code would still work.

    As I said before, changing the 'c' in 'Control' means that it's been used as a name, somewhere; that's the only time, to my knowledge, that the Access Gnomes exhibit this behavior. Tracking something like this down can really be time-consuming, especially in a big app. You have to schlep through every Form, Report and Module (class and standard) as well as all Queries and SQL Statements. I think using the binoculars ('Find') with the 'Search' Option set to Current Project, will search the first three listed, but not Queries and SQL Statements; they have to actually be eyeballed, if I remember correctly.

    Linq ;0)>

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    That search for 'current project' is only in the VBA editor to search code. To search through Access objects need a third party add-in like Rick Fisher's Find & Replace for about $50. Saved my sanity more than once.

    Code to set textbox property won't work for Continuous or Datasheet view. Need Conditional Formatting for that.
    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.

  8. #8
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by June7 View Post

    ...Code to set textbox property won't work for Continuous or Datasheet view...
    Except if you're Locking or Locking and Disabling the Control. It works, for these, placed in the Form_Current event, because neither

    ControlName.Locked = True

    nor

    Locked = True
    Enable = False


    changes the appearance of the Control!

    The target Control, on all Records will be Locked/Disabled or Unlocked/Enabled, conditionally, according to the current Record. But since it will format appropriately when you move to a given Record, and the formatting only matters when you're actually on that Record, it'll work for that.

    Linq ;0)>

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    True, I was over-generalizing. Nice clarification, linq.
    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. Looping Through Controls to Check Values
    By mcktigger in forum Programming
    Replies: 3
    Last Post: 01-25-2013, 12:05 PM
  2. Looping through continuous Form subforms
    By yahoo in forum Programming
    Replies: 1
    Last Post: 01-10-2013, 06:22 PM
  3. Replies: 2
    Last Post: 08-28-2012, 03:43 PM
  4. Looping through records in a continous form
    By accessnihon in forum Forms
    Replies: 3
    Last Post: 01-04-2012, 01:04 AM
  5. Replies: 0
    Last Post: 02-13-2011, 02:55 PM

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