Results 1 to 4 of 4

Thread: Eliminate Extra Code with possible array??

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 1999
    Posts
    154
    I have the following code:

    ***********************************
    Dim sForm as string

    If sForm = "A" then
    A.ADOD1.Recordset = "SQLQuery"
    end if

    If sForm = "I" then
    I.ADODC1.Recordset = "SQLQuery"
    end if
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

    The only difference between the two IF statements is the Form Name of either A or I at the begining of the .ADODC1 statement. I hope there is a way to eliminate the IF statements so that the code looks like the following:


    ***********************************
    Dim s as string

    s = "A" (or I may want it to be "I")

    S.ADOD1.Recordset = "SQLQuery"

    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


    This way I can eliminate the if statements. How do I do it so that S represents the proper ADODC1 control on the proper form???


    Thanks for any help

  2. #2
    Guest
    You could use IIf.

    Code:
    Dim frmTemp As Form
    Set frmTemp = IIf(sForm = "A", frmA, frmB)
    frmTemp.ADOD1.Recordset = "SQLQuery"
    IIf
    IIf(expr, truepart, falsepart)

    IIf always evaluates both truepart and falsepart, even though it returns only one of them. Because of this, you should watch for undesirable side effects. For example, if evaluating falsepart results in a division by zero error, an error occurs even if expr is True.

  3. #3
    Lively Member
    Join Date
    Dec 1999
    Location
    Karlsruhe, Germany
    Posts
    122
    Hi,

    if you could deside to use the forms name, try this:

    Code:
    Dim tmpform As Form
    For Each tmpform In Forms
        If tmpform.Name = sName Then
           tmpform.ADOD1.Recordset = "SQLQuery"
           Exit For
        End If
    Next
    otherwise define a public variable in the forms like "myname" and write:

    Code:
    Dim tmpform As Form
    For Each tmpform In Forms
        If tmpform.myName = sName Then
           tmpform.ADOD1.Recordset = "SQLQuery"
           Exit For
        End If
    Next
    Roger

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Sep 1999
    Posts
    154
    Thanks for the replys. From what I gather I can not use a string value of "A" or "I" and substitute it in place of

    S = "A"

    S.adodc1.recordset

    I must DIM S as Form first. This makes sense and I should have realized it.

    Thanks for all your help

Posting Permissions

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



Click Here to Expand Forum to Full Width