Results 1 to 6 of 6
  1. #1
    asmores is offline Novice
    Windows 2K Access 2003
    Join Date
    Mar 2013
    Posts
    20

    Textbox Control Source

    How can I change a textbox control source with vba based on a concate formula?
    I have a database that loops through user defined criteria and exports to excel. The user can fill in up to 100 different textboxes, but rather than assign a different query to each text box, I'd rather use 1 hidden text box that pivots through each textbox. Can anyone see the error in my code below. I feel its something simple but I cant place my finger on it.

    Thanks

    Private Sub Command2_Click()
    ct = 1
    Do Until ct = 101
    Me.tbloop.ControlSource = """=[Forms]![fTop]![tb" & Format(ct, "000") & "]"""
    Me.tbLoopName.ControlSource = """=[Forms]![fTop]![tb" & Format(ct, "000") & "Name]"""


    MsgBox ct
    MsgBox Me.tbloop.ControlSource
    Call ExporttoExcel
    ct = ct + 1
    Loop
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Do you want the value of each textbox or the textbox name?

    To set ControlSource to an expression that references textbox name:

    Me.tbloop.ControlSource = "=[tb" & Format(ct, "000") & "]"
    Me.tbLoopName.ControlSource = "=[Forms]![fTop]![tb" & Format(ct, "000") & "Name]"

    The [Forms]![fTop] prefix is not needed if all controls are on the same form.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    asmores is offline Novice
    Windows 2K Access 2003
    Join Date
    Mar 2013
    Posts
    20
    I would need the value of the textbox
    i tried this below

    Me.tbloop.Value = "=[tb" & Format(ct, "000") & "]"
    Me.tbLoopName.Value = "=[Forms]![fTop]![tb" & Format(ct, "000") & "Name]"

    its only showing the formula and not the user prompt.

    thank you,

  4. #4
    asmores is offline Novice
    Windows 2K Access 2003
    Join Date
    Mar 2013
    Posts
    20
    This works below but id rather loop if possible, i dont understand why the concatenate formula is not understood
    Me.tbloop = Me.tb001
    Me.tbLoopName = Me.tb001Name
    Call ExporttoExcel
    Me.tbloop = Me.tb002
    Me.tbLoopName = Me.tb002Name
    Call ExporttoExcel
    Me.tbloop = Me.tb003
    Me.tbLoopName = Me.tb003Name
    Call ExporttoExcel
    Me.tbloop = Me.tb004
    Me.tbLoopName = Me.tb004Name
    Call ExporttoExcel
    Me.tbloop = Me.tb005
    Me.tbLoopName = Me.tb005Name
    Call ExporttoExcel
    ...

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    What user prompt?

    Why are you now setting the Value property and before you were setting the ControlSource property?


    If you want the value of textbox, try:

    Me.tbloop = Me.Controls("tb" & Format(ct, "000"))
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    asmores is offline Novice
    Windows 2K Access 2003
    Join Date
    Mar 2013
    Posts
    20
    Works thank you, still new to this so 70% of what i do is just guess and check, i appreciate it

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Change a Control Source of a textbox VBA
    By WickidWe in forum Forms
    Replies: 1
    Last Post: 01-05-2014, 03:01 PM
  2. Replies: 12
    Last Post: 12-10-2013, 08:57 PM
  3. Textbox Control Source As Field Input
    By Jester0001 in forum Forms
    Replies: 4
    Last Post: 03-02-2012, 10:50 AM
  4. Replies: 17
    Last Post: 02-08-2012, 10:06 AM
  5. Textbox Control Source As An Expression help!
    By emilyrogers in forum Forms
    Replies: 11
    Last Post: 02-11-2011, 07:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums