Results 1 to 4 of 4
  1. #1
    ts_hunter is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    30

    Post Referencing form fields with a string variable

    I have a form with 3 contacts (Contacts 1, 2, & 3). Each contact has a name, address, and phone number. Above each contact, I have a check box to indicate if it should be used or not.

    I would like to have one section of code to load this form when I pull it up, instead of loading contact 1, then 2, then 3.


    The code below is what I found. What I want it to do is for i = 1 to 3, if the contact is not active, set visible to False. What am I not doing right.

    for i = 1 to 3
    if me.Controls("contact" & i.tostring & "_active") = true then


    me.Controls("contact" & i.tostring & "_name").visible = false
    me.Controls("contact" & i.tostring & "_city").visible = false
    me.Controls("contact" & i.tostring & "_state").visible = false
    me.Controls("contact" & i.tostring & "_phone").visible = false
    end if
    next i

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    It isn't clear what exactly you are trying to do.
    Do you want a list of contacts?
    You could put them in a comboBox or a listbox.
    You could select a contact from the list.

    Is any of this similar to what you're trying to do?

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Why are you using "if me.Controls("contact" & i.tostring & "_active") = true then"

    Try
    if me.Controls("contact" & i & "_active") = true then
    me.Controls("contact" & i & "_name").visible = false
    me.Controls("contact" & i & "_city").visible = false
    me.Controls("contact" & i & "_state").visible = false
    me.Controls("contact" & i & "_phone").visible = false

  4. #4
    ts_hunter is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    30
    Quote Originally Posted by ssanfu View Post
    Why are you using "if me.Controls("contact" & i.tostring & "_active") = true then"

    Try
    if me.Controls("contact" & i & "_active") = true then
    me.Controls("contact" & i & "_name").visible = false
    me.Controls("contact" & i & "_city").visible = false
    me.Controls("contact" & i & "_state").visible = false
    me.Controls("contact" & i & "_phone").visible = false
    That worked. Thanks. I used that same code in a couple spots, here it is.


    Click image for larger version. 

Name:	snip98.JPG 
Views:	6 
Size:	52.6 KB 
ID:	15367

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

Similar Threads

  1. Replies: 2
    Last Post: 01-18-2014, 11:51 AM
  2. Using Variable String to Set a Form object
    By neo651 in forum Programming
    Replies: 17
    Last Post: 07-08-2013, 12:59 PM
  3. Replies: 3
    Last Post: 05-28-2013, 12:53 PM
  4. Replies: 3
    Last Post: 12-02-2011, 04:14 PM
  5. Replies: 4
    Last Post: 05-16-2011, 04:58 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