Results 1 to 3 of 3
  1. #1
    shod90 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2016
    Posts
    134

    Change Button caption based on criteria from table.

    Dear All,


    I need to replace button captions to get the values from table based on criteria
    Code:
    Private Sub Form_Load()
    On Error Resume Next
    Dim rst As Recordset
    Dim ctl As Control
    Set rst = CurrentDb.OpenRecordset("Select * from products where easy =-1"): rst.MoveLast: rst.MoveFirst
    For Each ctl In Me.Controls
        If Not rst.EOF Then
            ctl.Caption = rst(3): ctl.Tag = rst(1): ctl.Enabled = True: ctl.Visible = True: ctl.OnClick = ""
            rst.MoveNext
        Else
            ctl.Visible = False
        End If
    Next
    
    
    End Sub

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    perhaps show an example of what you mean. label captions/tags can only have one value so based on your code, it will be changed for each row of your recordset i.e. only the last one will be applied. It will error if you have controls which don't have captions such as textboxes - and all controls will have the same 'values'

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    Why would button caption need to be based on data? If this is a single button in Detail Section and you want each record to show different caption on button then this is definitely not possible because there is only one button. And why would caption be based on recordset instead of data on form? A textbox can be formatted to look and act like a button.
    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.

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

Similar Threads

  1. Replies: 8
    Last Post: 05-08-2020, 10:38 AM
  2. Replies: 12
    Last Post: 11-22-2015, 02:34 PM
  3. Replies: 6
    Last Post: 09-22-2015, 01:18 PM
  4. Replies: 6
    Last Post: 01-16-2013, 12:12 PM
  5. Replies: 0
    Last Post: 01-12-2011, 12:43 PM

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