Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2010
    Posts
    22

    Unanswered: Hide/Show subforms depending on the value in a Field

    I have a form which contains two subforms nested one on top of the other. I want to show one subform if the field "Line" contains one value and the other if the "Line" field contains another value (the "Line" field either contains a 3 or an 8)

    I have done this on another form using this code and it works:
    Code:
    Private Sub Form_Current()
    If Me.Line = 3 Then         
        Me.Line_3_Perini_Settings_subform.Visible = True
        Me.Line_3_Bundler_subform.Visible = True
        Me.Line_8_Perini_Settings_subform.Visible = False 
        Me.L8_Bundler_subform.Visible = False
    End If
    If Me.Line = 8 Then          
        Me.Line_8_Perini_Settings_subform.Visible = True 
        Me.L8_Bundler_subform.Visible = True
        Me.Line_3_Perini_Settings_subform.Visible = False
        Me.Line_3_Bundler_subform.Visible = False
    End If
    
    
    End Sub
    However, on the current form I am building the following code doesn't work and I can't for the life of me figure out why:

    Code:
    Private Sub Form_Current()
    If Line = 3 Then
        Me.L3B_Product_Change_subform_p1.Visible = True
        Me.L8B_Product_Change_subform_p1.Visible = False
    End If
    If Line = 8 Then
        Me.L8B_Product_Change_subform_p1.Visible = True
        Me.L3B_Product_Change_subform_p1.Visible = False
    End If
    
    End Sub
    I can get it to work if I use conditions on a checkbox, but the "Line" Field value reference refuses to work.

    Any help will be greatly appreciated.
    Thanks,
    Dan

  2. #2
    Join Date
    Oct 2009
    Posts
    340
    if you are saying that Line = 3 never works then probably because 3 is not a number but rather text....so try Line like "3" and see if that works

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    first off check if there is a value in line
    check if you are using option explicit to report na error if a variable / object is referenced without being declared
    you have used different notation between the two calls

    as line =3 or =8 are mutually exclusive values then you should use an if elseif or a select czase construct

    Code:
    If me.Line = 3 Then
        Me.L3B_Product_Change_subform_p1.Visible = True
        Me.L8B_Product_Change_subform_p1.Visible = False
    else If me.Line = 8 Then
        Me.L8B_Product_Change_subform_p1.Visible = True
        Me.L3B_Product_Change_subform_p1.Visible = False
    else
    'decide what to do if line is neither 3 or 8
    End If
    put a watch/breakpoint on the line code and see what happens, see what values are in line
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Mar 2010
    Posts
    22
    Thanks for the replies.

    NTC,
    if you are saying that Line = 3 never works then probably because 3 is not a number but rather text....so try Line like "3" and see if that works
    I tried like and I tried formatting the field as a number....no luck.

    healdem,
    first off check if there is a value in line
    Line has a value in every record.

    check if you are using option explicit to report na error if a variable / object is referenced without being declared
    you have used different notation between the two calls
    I'm fairly new to VBA and I don't really understand this statement.

    I tried your code and still no luck. I also tried the watch/breakpoint but nothing showed in the immediate window, not sure how to run it from the code builder to watch it "live". Tried run to cursor and other things but it didn't seem to be doing anything.

    Like I said Line has a value of 3 or 8 in every record.

    Any other suggestions?

    Thanks again,
    Dan

  5. #5
    Join Date
    Mar 2010
    Posts
    22

    Problem solved.

    I decided to start from scratch with this form and gues what.....

    Code:
    Private Sub Form_Current()
    If Me.Line = 3 Then
        Me.L3B_Product_Change_subform_p1.Visible = True
        Me.L8B_Product_Change_subform_p1.Visible = False
    End If
    If Me.Line = 8 Then
        Me.L8B_Product_Change_subform_p1.Visible = True
        Me.L3B_Product_Change_subform_p1.Visible = False
    End If
    
    End Sub
    Works!

    I knew the code was ok because it was functioning in a previous form that I've built. I think something happened when I cut and paste fields off the main form into the first subform I built. Funnily though, it's the same subform I'm working with.

    Wierd.

    Thanks anyway,
    Dan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •