Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Some problem with a "For each" loop

Discussion in 'Information Technology' started by mbiconne@hotmail.com, Jul 28, 2006.

  1. mbiconne@hotmail.com

    mbiconne@hotmail.com
    Expand Collapse
    Guest

    Hi,

    I need to make visible or not some label or textbox, according to the
    value of a master label.

    I tought that an "Each ... for" loop could be the solution but it
    doesn't work.

    Belove an example of the code:

    txt = Des_Articolo
    frm = [Form_DET_ART]

    For Each txt In frm
    If txt.Value = "zip" Then
    Des_Caratteristica_2.Visible = False
    Num_Taglia.Visible = True
    Cda_Colore_Finissaggio.Visible = True
    Num_Grana.Visible = True
    Des_Posizione.Visible = True
    Num_Cursore_txt.Visible = True
    Num_Lunghezza.Visible = True
    Flg_Divisibile_txt_2.Visible = True
    Flg_Tiretto_txt_2.Visible = False
    Else
    Num_Taglia.Visible = False
    Cda_Colore_Finissaggio.Visible = False
    Num_Grana.Visible = False
    Des_Posizione.Visible = False
    Num_Cursore_txt.Visible = False
    Num_Lunghezza.Visible = False
    Flg_Divisibile_txt_2.Visible = False
    Flg_Tiretto_txt_2.Visible = False
    End If
    next

    Any ideas?
     
  2. Loading...


  3. Arvin Meyer [MVP]

    Arvin Meyer [MVP]
    Expand Collapse
    Guest

    Dim frm As Form
    Dim ctl As Control

    For Each ctl in frm.Controls
    If TypeOf ctl = acTextbox Then
    If ctl.Value = "zip" Then


    or For Each may not be necessary since you only need to change the visible
    property once.

    If Me.ControlName = "zip" Then
    --
    Arvin Meyer, MCP, MVP
    Microsoft Access
    Free Access downloads
    http://www.datastrat.com
    http://www.mvps.org/access

    <mbiconne@hotmail.com> wrote in message
    news:1147429753.315764.134050@g10g2000cwb.googlegroups.com...
    > Hi,
    >
    > I need to make visible or not some label or textbox, according to the
    > value of a master label.
    >
    > I tought that an "Each ... for" loop could be the solution but it
    > doesn't work.
    >
    > Belove an example of the code:
    >
    > txt = Des_Articolo
    > frm = [Form_DET_ART]
    >
    > For Each txt In frm
    > If txt.Value = "zip" Then
    > Des_Caratteristica_2.Visible = False
    > Num_Taglia.Visible = True
    > Cda_Colore_Finissaggio.Visible = True
    > Num_Grana.Visible = True
    > Des_Posizione.Visible = True
    > Num_Cursore_txt.Visible = True
    > Num_Lunghezza.Visible = True
    > Flg_Divisibile_txt_2.Visible = True
    > Flg_Tiretto_txt_2.Visible = False
    > Else
    > Num_Taglia.Visible = False
    > Cda_Colore_Finissaggio.Visible = False
    > Num_Grana.Visible = False
    > Des_Posizione.Visible = False
    > Num_Cursore_txt.Visible = False
    > Num_Lunghezza.Visible = False
    > Flg_Divisibile_txt_2.Visible = False
    > Flg_Tiretto_txt_2.Visible = False
    > End If
    > next
    >
    > Any ideas?
    >
     
  4. mbic

    mbic
    Expand Collapse
    Guest

    Hi I tried to use the code you suggested but it does not work...

    VB doesn't accept the string " If TypeOf ctl = acTextbox Then ", is it
    correct?
     
  5. Douglas J Steele

    Douglas J Steele
    Expand Collapse
    Guest

    Arvin's code looks correct to me. Let's see your code to ensure you didn't
    misinterpret him.

    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)


    "mbic" <mbiconne@hotmail.com> wrote in message
    news:1148384995.382704.259250@u72g2000cwu.googlegroups.com...
    > Hi I tried to use the code you suggested but it does not work...
    >
    > VB doesn't accept the string " If TypeOf ctl = acTextbox Then ", is it
    > correct?
    >
     
  6. Rick Wannall

    Rick Wannall
    Expand Collapse
    Guest

    Take the "ac" off the acTextbox. When using the TypeOf operator you choose
    from a popup list of possible values. The values are types, not Access
    constants. The list has values such as ComboBox, ListBox, TextBox, etc, not
    acComboBox, acListBox and acTextbox.
     
  7. mbic

    mbic
    Expand Collapse
    Guest

    Thanks to everybody for your help!!

    This is the situation:

    I tried to use the code suggested, with some change to understand the
    result

    Dim frm As Form
    Dim ctl As Control

    ctl = Des_Articolo

    For Each ctl In Me.Controls
    If TypeOf ctl Is TextBox Then
    If ctl.Value = "zip" Then
    MsgBox (ctl.Value)
    Else
    MsgBox (ctl.Value)
    End If
    End If
    Next

    but I receive the run-time error number "91"

    VB ask for a with variable...

    What's wrong?
     
  8. Brendan Reynolds

    Brendan Reynolds
    Expand Collapse
    Guest

    Object variables need to be assigned using the 'Set' key word. See the
    commented line below ...

    Set ctl = Des_Articolo '<---

    For Each ctl In Me.Controls
    If TypeOf ctl Is TextBox Then
    If ctl.Value = "zip" Then
    MsgBox (ctl.Value)
    Else
    MsgBox (ctl.Value)
    End If
    End If
    Next

    --
    Brendan Reynolds
    Access MVP

    "mbic" <mbiconne@hotmail.com> wrote in message
    news:1148634760.422686.232170@j33g2000cwa.googlegroups.com...
    > Thanks to everybody for your help!!
    >
    > This is the situation:
    >
    > I tried to use the code suggested, with some change to understand the
    > result
    >
    > Dim frm As Form
    > Dim ctl As Control
    >
    > ctl = Des_Articolo
    >
    > For Each ctl In Me.Controls
    > If TypeOf ctl Is TextBox Then
    > If ctl.Value = "zip" Then
    > MsgBox (ctl.Value)
    > Else
    > MsgBox (ctl.Value)
    > End If
    > End If
    > Next
    >
    > but I receive the run-time error number "91"
    >
    > VB ask for a with variable...
    >
    > What's wrong?
    >
     
  9. Douglas J Steele

    Douglas J Steele
    Expand Collapse
    Guest

    Of course, since that particular instantiation of ctl doesn't get used at
    all (the next line resets it...), the highlighted line could just be
    deleted.

    I don't understand what the code is supposed to be doing. It's going to pop
    up a bunch of message boxes, each containing the value contained in one text
    box on the form, regardless of whether or not the text box contains the word
    "zip" in it.

    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)


    "Brendan Reynolds" <brenreyn@discussions.microsoft.com> wrote in message
    news:%23egtmoKgGHA.1264@TK2MSFTNGP05.phx.gbl...
    > Object variables need to be assigned using the 'Set' key word. See the
    > commented line below ...
    >
    > Set ctl = Des_Articolo '<---
    >
    > For Each ctl In Me.Controls
    > If TypeOf ctl Is TextBox Then
    > If ctl.Value = "zip" Then
    > MsgBox (ctl.Value)
    > Else
    > MsgBox (ctl.Value)
    > End If
    > End If
    > Next
    >
    > --
    > Brendan Reynolds
    > Access MVP
    >
    > "mbic" <mbiconne@hotmail.com> wrote in message
    > news:1148634760.422686.232170@j33g2000cwa.googlegroups.com...
    > > Thanks to everybody for your help!!
    > >
    > > This is the situation:
    > >
    > > I tried to use the code suggested, with some change to understand the
    > > result
    > >
    > > Dim frm As Form
    > > Dim ctl As Control
    > >
    > > ctl = Des_Articolo
    > >
    > > For Each ctl In Me.Controls
    > > If TypeOf ctl Is TextBox Then
    > > If ctl.Value = "zip" Then
    > > MsgBox (ctl.Value)
    > > Else
    > > MsgBox (ctl.Value)
    > > End If
    > > End If
    > > Next
    > >
    > > but I receive the run-time error number "91"
    > >
    > > VB ask for a with variable...
    > >
    > > What's wrong?
    > >

    >
    >
     
  10. Brendan Reynolds

    Brendan Reynolds
    Expand Collapse
    Guest

    Yes, I know, the code as posted doesn't make sense. But the original poster
    did say "I tried to use the code suggested, with some change to understand
    the result". I'm taking this to mean that the original poster is playing
    around with the code in an attempt to understand the suggestion better, so
    it may not necessarily be intended to make practical sense at this stage. I
    could, of course, be wrong.

    --
    Brendan Reynolds
    Access MVP

    "Douglas J Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
    news:OGB1hNLgGHA.3364@TK2MSFTNGP05.phx.gbl...
    > Of course, since that particular instantiation of ctl doesn't get used at
    > all (the next line resets it...), the highlighted line could just be
    > deleted.
    >
    > I don't understand what the code is supposed to be doing. It's going to
    > pop
    > up a bunch of message boxes, each containing the value contained in one
    > text
    > box on the form, regardless of whether or not the text box contains the
    > word
    > "zip" in it.
    >
    > --
    > Doug Steele, Microsoft Access MVP
    > http://I.Am/DougSteele
    > (no e-mails, please!)
    >
    >
    > "Brendan Reynolds" <brenreyn@discussions.microsoft.com> wrote in message
    > news:%23egtmoKgGHA.1264@TK2MSFTNGP05.phx.gbl...
    >> Object variables need to be assigned using the 'Set' key word. See the
    >> commented line below ...
    >>
    >> Set ctl = Des_Articolo '<---
    >>
    >> For Each ctl In Me.Controls
    >> If TypeOf ctl Is TextBox Then
    >> If ctl.Value = "zip" Then
    >> MsgBox (ctl.Value)
    >> Else
    >> MsgBox (ctl.Value)
    >> End If
    >> End If
    >> Next
    >>
    >> --
    >> Brendan Reynolds
    >> Access MVP
    >>
    >> "mbic" <mbiconne@hotmail.com> wrote in message
    >> news:1148634760.422686.232170@j33g2000cwa.googlegroups.com...
    >> > Thanks to everybody for your help!!
    >> >
    >> > This is the situation:
    >> >
    >> > I tried to use the code suggested, with some change to understand the
    >> > result
    >> >
    >> > Dim frm As Form
    >> > Dim ctl As Control
    >> >
    >> > ctl = Des_Articolo
    >> >
    >> > For Each ctl In Me.Controls
    >> > If TypeOf ctl Is TextBox Then
    >> > If ctl.Value = "zip" Then
    >> > MsgBox (ctl.Value)
    >> > Else
    >> > MsgBox (ctl.Value)
    >> > End If
    >> > End If
    >> > Next
    >> >
    >> > but I receive the run-time error number "91"
    >> >
    >> > VB ask for a with variable...
    >> >
    >> > What's wrong?
    >> >

    >>
    >>

    >
    >
     

Share This Page