Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2004
    Location
    Cary, NC
    Posts
    264

    Unanswered: Change button picture in code

    I need to provide the ability for the user to determine the sort order of a recordset. I wanted to provide a button that would toggle between ascending and descending. This button begins with a picture of an UP arrow. When it is clicked, I want to change the picture to a DOWN arrow. The properties for the button picture returns "(bitmap)", which isn't much help. Any thoughts on how to do this?

    I have 5 different fields that they can sort on and a lot of other information on the form, I am trying to keep the space used for sorting to a minimum.

  2. #2
    Join Date
    Oct 2003
    Location
    US
    Posts
    343
    Use this piece of code to change the button image

    cmdSort.Picture = "c:\Temp\Ascend.bmp"

  3. #3
    Join Date
    Aug 2004
    Location
    Cary, NC
    Posts
    264
    Sorry, I really didn't state what the issue was very good. It is more a problem of where the up/down arrow pictures are and how to keep the code working when different users access the form from different computers.

    Thanks.

  4. #4
    Join Date
    Oct 2003
    Location
    US
    Posts
    343
    do you have a BE/FE setup with FE on each pc or what?

  5. #5
    Join Date
    Aug 2004
    Location
    Cary, NC
    Posts
    264
    No, it is not split, just a simple database stored on a common drive. Generally it will only be used by two different people but I can't have it failing on me if someone else opens it.

    I got around the issue for now by creating two different buttons, one with an up arrow, one with a down and then I hide the one that I don't want. It isn't elegant but it works. I am taking a long weekend and needed to make it work before I left.

  6. #6
    Join Date
    Oct 2003
    Location
    US
    Posts
    343
    If you have one application and multiple user logging in at the same time then how can this flip flop logic will work!!! Not possible. You need to make FE/BE setup if you want the image to toggle. Otherwise, whatever you are doing is good enough unless someone comes up with a better technique.

  7. #7
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    The way I did it, was to have a command button and put two images on top of the command button. When you hit the button once, the up arrow images is shown. When you hit it again the up arrow is hidden and the down arrow is shown. This way you don't actually modify what picture is associated with the button and you only have one command button to put logic in. I can post the code if you want, but there is alot going on with it.

  8. #8
    Join Date
    Aug 2004
    Location
    Cary, NC
    Posts
    264

    Code would be helpful

    Quote Originally Posted by DCKunkle
    The way I did it, was to have a command button and put two images on top of the command button. When you hit the button once, the up arrow images is shown. When you hit it again the up arrow is hidden and the down arrow is shown. This way you don't actually modify what picture is associated with the button and you only have one command button to put logic in. I can post the code if you want, but there is alot going on with it.
    I would like to see the code for doing this if you wouldn't mind. It sounds like what I want to do. Due to the nature of the database only one person will be using it at a time so I will not have to worry about that issue.

    Thanks.

    Steve.

  9. #9
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    Here is the code from behind the form. I have also attached a picture of the form.

    Code:
    Option Compare Database
    Option Explicit
    
    Dim intControlHasFocus As Integer
    
    Const intSortType As Integer = 1
    Const intSortCode As Integer = 2
    Const intSortDescription As Integer = 3
    Const intSortCreated As Integer = 4
    
    Const strSortAscending As String = "1"
    Const strSortDescending As String = "2"
    
    Private Sub cboClient_AfterUpdate()
    
        If IsNull(cboClient) Then
            Me.sfrmEditorComponent.Form.FilterOn = True
            Me.sfrmEditorComponent.Form.Filter = ""
        Else
            Me.sfrmEditorComponent.Form.FilterOn = True
            Me.sfrmEditorComponent.Form.Filter = "ComponentClientID=" & cboClient
        End If
        
    End Sub
    
    Private Sub cmdClose_Click()
    
        DoCmd.Close acForm, Me.Name
        
    End Sub
    
    Private Sub cmdEditComponent_Click()
        
        If Not IsNull(Me.sfrmEditorComponent.Form!ComponentID) Then
            DoCmd.OpenForm "frmEditorComponentOne", , , "ComponentID=" & Me.sfrmEditorComponent.Form!ComponentID, acFormEdit, acDialog
            Me.sfrmEditorComponent.Form.Requery
        End If
        
    End Sub
    
    Private Sub cmdNewComponent_Click()
    
        DoCmd.OpenForm "frmEditorComponentOne", acNormal, , , acFormAdd, acDialog
        Me.sfrmEditorComponent.Form.Requery
        
    End Sub
    
    Private Sub lblCode_Click()
    
        'If this control had the focus before then sort descending rather than ascending
        If intControlHasFocus = intSortCode Then
            lblCode.Tag = IIf(lblCode.Tag = strSortAscending, strSortDescending, strSortAscending)
        Else
            lblCode.Tag = strSortAscending
        End If
        
        'Turn on the ordering, and sort by the Code
        Me.sfrmEditorComponent.Form.OrderBy = "ComponentCode " & IIf(lblCode.Tag = strSortAscending, "ASC", "DESC")
        Me.sfrmEditorComponent.Form.OrderByOn = True
    
        intControlHasFocus = intSortCode
        UpdateSortHeadings
    
    End Sub
    
    Private Sub lblCode_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
        lblCode.SpecialEffect = 2
        
    End Sub
    
    Private Sub lblCode_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
        lblCode.SpecialEffect = 1
        
    End Sub
    
    Private Sub lblCreated_Click()
    
        'If this control had the focus before then sort descending rather than ascending
        If intControlHasFocus = intSortCreated Then
            lblCreated.Tag = IIf(lblCreated.Tag = strSortAscending, strSortDescending, strSortAscending)
        Else
            lblCreated.Tag = strSortAscending
        End If
        
        'Turn on the ordering, and sort by the Created
        Me.sfrmEditorComponent.Form.OrderBy = "ComponentCreated " & IIf(lblCreated.Tag = strSortAscending, "ASC", "DESC")
        Me.sfrmEditorComponent.Form.OrderByOn = True
        
        intControlHasFocus = intSortCreated
        UpdateSortHeadings
    
    End Sub
    
    Private Sub lblCreated_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
        lblCreated.SpecialEffect = 2
        
    End Sub
    
    Private Sub lblCreated_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
        lblCreated.SpecialEffect = 1
        
    End Sub
    
    Private Sub lblDescription_Click()
    
        'If this control had the focus before then sort descending rather than ascending
        If intControlHasFocus = intSortDescription Then
            lblDescription.Tag = IIf(lblDescription.Tag = strSortAscending, strSortDescending, strSortAscending)
        Else
            lblDescription.Tag = strSortAscending
        End If
        
        'Turn on the ordering, and sort by the Description
        Me.sfrmEditorComponent.Form.OrderBy = "ComponentDescription " & IIf(lblDescription.Tag = strSortAscending, "ASC", "DESC")
        Me.sfrmEditorComponent.Form.OrderByOn = True
        
        intControlHasFocus = intSortDescription
        UpdateSortHeadings
    
    End Sub
    
    Private Sub lblDescription_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
        lblDescription.SpecialEffect = 2
        
    End Sub
    
    Private Sub lblDescription_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
        lblDescription.SpecialEffect = 1
        
    End Sub
    
    Private Sub lblType_Click()
        
        'If this control had the focus before then sort descending rather than ascending
        If intControlHasFocus = intSortType Then
            lblType.Tag = IIf(lblType.Tag = strSortAscending, strSortDescending, strSortAscending)
        Else
            lblType.Tag = strSortAscending
        End If
        
        'Turn on the ordering, and sort by the Type
        Me.sfrmEditorComponent.Form.OrderBy = "ComponentType " & IIf(lblType.Tag = strSortAscending, "ASC", "DESC")
        Me.sfrmEditorComponent.Form.OrderByOn = True
        
        intControlHasFocus = intSortType
        UpdateSortHeadings
        
    End Sub
    
    Private Sub lblType_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
        lblType.SpecialEffect = 2
        
    End Sub
    
    Private Sub lblType_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
        lblType.SpecialEffect = 1
        
    End Sub
    
    Public Sub UpdateSortHeadings()
    
        HideAllGraphics
        
        Select Case intControlHasFocus
        
            Case intSortType
                If lblType.Tag = strSortAscending Then
                    imgTypeUp.Visible = True
                Else
                    imgTypeDown.Visible = True
                End If
            
            Case intSortCode
                If lblCode.Tag = strSortAscending Then
                    imgCodeUp.Visible = True
                Else
                    imgCodeDown.Visible = True
                End If
            
            Case intSortDescription
                If lblDescription.Tag = strSortAscending Then
                    imgDescriptionUp.Visible = True
                Else
                    imgDescriptionDown.Visible = True
                End If
             
            Case intSortCreated
                If lblCreated.Tag = strSortAscending Then
                    imgCreatedUp.Visible = True
                Else
                    imgCreatedDown.Visible = True
                End If
            
        End Select
        
    End Sub
    
    Public Sub HideAllGraphics()
    
        imgTypeUp.Visible = False
        imgTypeDown.Visible = False
        
        imgCodeUp.Visible = False
        imgCodeDown.Visible = False
        
        imgDescriptionUp.Visible = False
        imgDescriptionDown.Visible = False
        
        imgCreatedUp.Visible = False
        imgCreatedDown.Visible = False
        
    End Sub
    Attached Thumbnails Attached Thumbnails Component.jpg  

Posting Permissions

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