Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2004
    Posts
    44

    Unanswered: Sequential String Operator?

    I'm trying to get my form to recognize x, y, z, etc. "on open". My initial If, Then statement works, however, after the initial statement has been recognized and processed I'm thinking the rest of the code is ignored. I think that I need some sort of operator that will basically tell access to (a) and (b) and (c), etc. However, I know it's not "and". =) I'd greatly appreciate some help.

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Could you post the code, the input, and your desired result?

  3. #3
    Join Date
    Jan 2004
    Posts
    44
    Well this is what I'm working with right now.

    Private Sub Form_Open(Cancel As Integer)

    If Me![ProgramNumbers] = 1 Then
    Me![02].Visible = False
    ElseIf Me![ProgramNumbers] = 1 Then
    Me![03].Visible = False
    End If

    With that entered, I open the the form, but only subform [02] is not visable. [03] is still there. (Btw, ProgramNUmbers is the combo box that is on the form, and the default is currently set to 1).

    Ideally, what I want to happen, for now, is that when I open the form only subform [01] is showing. Then, for example, if I select 3 from the combo box, subforms [02] and [03] will appear.

  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Oh, ok. Yeah you were right, after the first "if" completes, it terminates. You could do this in stages, like so:

    Basically you have three different possible outcomes, assuming I understand you correctly. So you have to include a condition for each:

    Code:
    if Me![ProgramNumbers] =3 Then       
        me![03].Visible = True
        me![02].Visible = True
    ElseIf Me![ProgramNumbers] = 2 Then
       me![03].Visible = False
       me![02].Visible = True
    Else
       me![03].Visible = False
       me![02].Visible = False
    End If

  5. #5
    Join Date
    Jan 2004
    Posts
    44
    That sounds and looks like it will work. However, if I use that method, does that mean I will not have to have an AfterUpdate in the ComboBox properties? Or will something like that still apply? Otherwise, how will anything be able to change from the default of 1?

    [edit] - how do the tabs affect the statements. Also, would I still only have 3 statement headers: If, Elseif, and Else? Or would I have to have 3 of those for each of 13 subforms that there are?
    Last edited by Superman07; 02-02-04 at 17:28.

  6. #6
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Originally posted by Superman07
    That sounds and looks like it will work. However, if I use that method, does that mean I will not have to have an AfterUpdate in the ComboBox properties? Or will something like that still apply? Otherwise, how will anything be able to change from the default of 1?
    That could would go IN the AfterUpdate for the combobox. Everytime you change the combobox it would fire.

    how do the tabs affect the statements. Also, would I still only have 3 statement headers: If, Elseif, and Else? Or would I have to have 3 of those for each of 13 subforms that there are?
    Uh.. I'm not sure what you're getting at here.. do you need to reuse this code 13 times? If so, you may want to declare it as a function and pass the subform as a parameter. Then you can call it on all 13 forms, assuming all the controls are named identically.

    Something like:
    Code:
    Function yourFunction(frm AS form)
    
    if frm![ProgramNumbers] =3 Then       
        frm![03].Visible = True
        frm![02].Visible = True
    ElseIf frm![ProgramNumbers] = 2 Then
       frm![03].Visible = False
       frm![02].Visible = True
    Else
       frm![03].Visible = False
       frm![02].Visible = False
    End If
    Then you could place:

    yourFunction(me)

    in the AfterUpdate event of the comboboxes. I'm sort of guessing at your setup though, let me know.
    Last edited by Teddy; 02-02-04 at 17:39.

  7. #7
    Join Date
    Jan 2004
    Posts
    44
    Well the good news is that I figured out why the afterupdate was not working previously - I had some syntax wrong... =/

    However, back to the possible need for a function. What I have are 13 subforms, [01]-[13]. What I want to code to say (in laymans terms), is: If combo box value is 1, then 01 is visible and 2-13 are not. If I update combo box to anything other than 1, I want all subforms that are equal to, or lesser than the new combo box number to appear.

    Example: I now pick 13, I want all subforms to appear.

    Example: I pick 7, I want 1-7 to appear.

    Given what you said I'm confused if I would need to have

    Function yourFunction(frm AS form)

    if frm![ProgramNumbers] =3 Then
    frm![13]...false
    frm![12]...false
    .
    .
    .
    .
    frm![03].Visible = True
    frm![02].Visible = True
    ElseIf frm![ProgramNumbers] = 2 Then
    frm![13]...false
    frm![03].Visible = False
    frm![02].Visible = True
    Else
    frm![03].Visible = False
    frm![02].Visible = False
    End If

    Or would I need to have the whole set 13 times, where each starts with "if frm![ProgramNumbers] =3 Then", and I would change = X each time and the code under it would alter, i.e.,

    if frm![ProgramNumbers] =7 Then
    frm![08].visible = false
    frm![07].visible = True
    frm![06].visible = True
    frm![06].visible = True
    frm![05].visible = True
    frm![04].visible = True
    frm![03].Visible = True
    frm![02].Visible = True
    ElseIf frm![ProgramNumbers] = 5 Then
    frm![08].visible = false
    frm![07].visible = false
    frm![06].visible = false
    frm![06].visible = True
    frm![05].visible = True
    frm![04].visible = True
    frm![03].Visible = True
    frm![02].Visible = True
    Else
    frm![03].Visible = False
    frm![02].Visible = False
    End If
    (not sure here what the last else is for).

    If you need clarification or I'm not not making sense please let me know. I appreciate the help though. It's helping me a lot.
    Last edited by Superman07; 02-03-04 at 10:52.

  8. #8
    Join Date
    Jan 2004
    Posts
    44
    Well I accomplished what I initially set out to do. I have my subforms appearing and disappearing depending on what number is selected from the combo box.

    I ended up tying out all of the code repeatedly, where each additional number has an Elseif statement. I was worried that, similar to before, access would stop after the first statement and not even see the others. However, it turns out you can have multiple elseif statments. N

    Now on to the next part!

    Thanks for the help!

    And yes, I'm sure there was an easier way to get this done...

Posting Permissions

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