Results 1 to 7 of 7

Thread: Function filling textboxes

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    The Netherlands
    Posts
    96

    Function filling textboxes

    I'd like to creat a function which fills in textboxes...
    The function should do something like this...
    txtVarType = rs.Fields("Type")
    txtVarPrice = rs.Fields("SalesPrice")
    txtVarDescr = rs.Fields("Description")

    txtVar2Type = rs.Fields("Type")
    txtVar2Price = rs.Fields("SalesPrice")
    txtVar2Descr = rs.Fields("Description")

    txtVar3Type = rs.Fields("Type")
    txtVar3Price = rs.Fields("SalesPrice")
    txtVar3Descr = rs.Fields("Description")

    I was thinking of somthing like this...

    Public Function Filltextbox(Fill As String)
    "txt" & Fill & "Type" = rs.Fields("Type")
    "txt" & Fill & "Price" = rs.Fields("SalesPrice")
    "txt" & Fill & "Descr" = rs.Fields("Description")
    End Function

    Initiating the function as follows...
    Filltextbox(Var)
    Filltextbox(Var2)
    Filltextbox(Var3)

    But this..."txt" & Fill & "Type" doesn't seem to work..Can anyone help?

  2. #2
    Addicted Member chatty's Avatar
    Join Date
    Aug 2002
    Location
    in a house
    Posts
    202
    Use control arrays

  3. #3
    Addicted Member chatty's Avatar
    Join Date
    Aug 2002
    Location
    in a house
    Posts
    202
    To do this:

    Public Function Filltextbox(Fill As integer)
    txtVarType(Fill) = rs.Fields("Type")
    txtVarTypePrice(Fill) = rs.Fields("SalesPrice")
    txtVarTypeDescr(Fill) = rs.Fields("Description")
    End Function

    Initiating the function as follows...
    Filltextbox(1)
    Filltextbox(2)
    Filltextbox(3)

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    The Netherlands
    Posts
    96

    What name to Textboxes?

    Ok now I have the follwoing code...

    Public Function Filltextbox(Fill As Integer)
    txtVarType(Fill) = "Bla"
    txtVarTypePrice(Fill) = "Blaat"
    txtVarTypeDescr(Fill) = "Blaatt"
    End Function

    Private Sub Command1_Click()
    Filltextbox (1)
    End Sub


    I have three textboxes...
    txtVarType1
    txtVarTypePrice1
    txtVarTypeDescr1

    When I try and run the code...it gives me the following error...
    "Sub or Function not defined."

    So what's wrong?!?

  5. #5
    Addicted Member chatty's Avatar
    Join Date
    Aug 2002
    Location
    in a house
    Posts
    202
    Check out the example
    Attached Files Attached Files

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    The Netherlands
    Posts
    96

    Thanks very much!

    Thank you very much...great help!

  7. #7
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Couple of ways to do this one, i'd use this one normally:
    Each conrtol on a form is a menber of the form.controls collection. You can call on this collection to reference your textbox :

    VB Code:
    1. Public Function Filltextbox(Fill As String)
    2.     me.controls("txt" & Fill & "Type")  = rs.Fields("Type")
    3.     me.controls(""txt" & Fill & "Price") = rs.Fields("SalesPrice")
    4.     me.controls(""txt" & Fill & "Descr") = rs.Fields("Description")
    5. End Function

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

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