Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2009
    Posts
    17

    Unanswered: Procedure problem

    elow, am just a beginner and a low class programmer.

    can anybody help me out of this problem?

    i have procedures like this..
    __________________________________________________ _______
    Sub C1TxtSerieses1()
    Me.txtseries1.Value = Me.txttag.Value & Me.txtname.value & Me.txtbday.Value & Me.txtsex.Value & Me.txtcardno.Value & Me.g1.Value & "." & Me.GX1.Value & Me.u1.Value & "." & Me.ux1.Value
    End Sub
    __________________________________________________ _______
    Sub C1TxtSerieses2()
    Me.txtseries2.Value = Me.txttag.Value & Me.txtname.value & Me.txtbday.Value & Me.txtsex.Value & Me.txtcardno.Value & Me.g2.Value & "." & Me.GX2.Value & Me.u2.Value & "." & Me.ux2.Value
    End Sub
    __________________________________________________ ________
    .
    .
    .
    .
    Sub C1TxtSerieses50()
    Me.txtseries50.Value = Me.txttag.Value & Me.txtname.value & Me.txtbday.Value & Me.txtsex.Value & Me.txtcardno.Value & Me.g50.Value & "." & Me.GX50.Value & Me.u50.Value & "." & Me.ux50.Value
    End Sub
    __________________________________________________ ________


    this simply write the concatenated values of the textboxes in 1 called txtseries. the problem is i have 50 procedure of this.. can anybody simplify the procedures in a single procedure. so that i can call only 1 procedure name.

    many thanks,
    btw am using msaccess

  2. #2
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    There are (at least) two solutions; the first is easiest to follow, but harder to maintain ie
    Code:
     Sub C1TxtSerieses(ByVal iIndex As Integer)
        Dim strTemp As String
        strTemp = Me.txttag.Value & Me.txtname.Value & Me.txtbday.Value & Me.txtsex.Value & Me.txtcardno.Value
        Select Case Index
            Case Is = 1
                Me.txtseries1.Value = strTemp & Me.g1.Value & "." & Me.GX1.Value & Me.u1.Value & "." & Me.ux1.Value
            Case Is = 2
                Me.txtseries2.Value = strTemp & Me.g2.Value & "." & Me.GX2.Value & Me.u2.Value & "." & Me.ux2.Value
                '
                '
                '
                '
            Case Is = 50
                Me.txtseries50.Value = strTemp & Me.g50.Value & "." & Me.GX50.Value & Me.u50.Value & "." & Me.ux50.Value
        End Select
    End Sub
    The second uses the form/objects Controls collection to reefer to the specific control, permitting a string argument that you can pass variable to. ie
    Code:
     Sub C1TxtSerieses(ByVal iIndex As Integer)
        Me.Controls("txtseries" & iIndex).Value = Me.txttag.Value & Me.txtname.Value & Me.txtbday.Value & Me.txtsex.Value & Me.txtcardno.Value & Me.Controls("g" & iIndex).Value & Me.Conrols("GX" & iIndex).Value & Me.Contrls("u" & iIndex).Value & "." & Me.Controls("ux" & iIndex).Value
    End Sub
    I would use the second.

    HTH

    MTB

  3. #3
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Also note that having controls named txtseries1, txtseries2...txtseries50 and the same for g1, g2...g50 and so forth smacks big time of a non-normalized database. I suspect that your basic database design is seriously flawed and will lead to numerous problems in the future.

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    Join Date
    Mar 2009
    Posts
    17
    thank you all for your kindness and support.
    i really appreciate it.

    @MTB will try all of this as soon as went home. and post if it works.

    @Missinglinq do you have any suggestion to work with my database more efficiently?

    more power to you guys

  5. #5
    Join Date
    Mar 2009
    Posts
    17
    @mtb thanks thanks thanks

    that's all i can say.. it really works.

    i chose 2nd option..

    cheers

Posting Permissions

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