none
HOW TO MAKE SUBFORM HAVE DOUBLECLICK EVENT/CHANGE INDIVIDUAL BACKGROUND COLORS? RRS feed

  • Question

  • 

    Hey boys, yesterday we solved how to have multiple records in one form using subforms. Now I'm trying to double click each subform and open up that record. Can you guys see anything wrong with it?

    There is no "on Dbl Click" on subform options, but I went into the subform itself and typed this code:

    Private Sub Form_DblClick(Cancel As Integer)
        Dim stDocName As String
        Dim stLinkCriteria As String
    
        stDocName = "frmContactDetails"
        stLinkCriteria = "[ID]=" & Me![txtID]
        
        DoCmd.OpenForm stDocName, , , stLinkCriteria
    End If
    End Sub



    • Edited by InnVis Friday, August 11, 2017 11:19 AM CONTINUED DISCUSSION
    Thursday, August 10, 2017 11:16 AM

Answers

  • 

    There is no "on Dbl Click" on subform options, but I went into the subform itself and typed this code:

    Private Sub Form_DblClick(Cancel As Integer)
        Dim stDocName As String
        Dim stLinkCriteria As String
    
        stDocName = "frmContactDetails"
        stLinkCriteria = "[ID]=" & Me![txtID]
        
        DoCmd.OpenForm stDocName, , , stLinkCriteria
    End If
    End Sub

    Hi Jamie,

    I am not sure whether the Me object works for a subform, because I do not use it in my systematics. But I suppose it is correct.

    If it is correct, then Me!txtID (no brackets needed) refers to a control on the subform, but probably you want a control on the main form. In that case you can use:    Me.Parent!txtID

    The DblClick will work then iof you click between the controls of the subform. If you want it to be effective "anywhere" on the subfirm, then you include it in all the control's DblClick events.

    Imb.

    • Marked as answer by InnVis Thursday, August 10, 2017 12:46 PM
    Thursday, August 10, 2017 11:46 AM

All replies

  • Gah, figured it out - apparently I have to have the subform "Enabled" and not "Locked" for the code to work. I just want to get rid of the highlights/cursor.
    Thursday, August 10, 2017 11:40 AM
  • 

    There is no "on Dbl Click" on subform options, but I went into the subform itself and typed this code:

    Private Sub Form_DblClick(Cancel As Integer)
        Dim stDocName As String
        Dim stLinkCriteria As String
    
        stDocName = "frmContactDetails"
        stLinkCriteria = "[ID]=" & Me![txtID]
        
        DoCmd.OpenForm stDocName, , , stLinkCriteria
    End If
    End Sub

    Hi Jamie,

    I am not sure whether the Me object works for a subform, because I do not use it in my systematics. But I suppose it is correct.

    If it is correct, then Me!txtID (no brackets needed) refers to a control on the subform, but probably you want a control on the main form. In that case you can use:    Me.Parent!txtID

    The DblClick will work then iof you click between the controls of the subform. If you want it to be effective "anywhere" on the subfirm, then you include it in all the control's DblClick events.

    Imb.

    • Marked as answer by InnVis Thursday, August 10, 2017 12:46 PM
    Thursday, August 10, 2017 11:46 AM
  • To make a form read-only set the Locked property of each bound control to True (Yes) and the Enabled property to False (No).  The user will not be able to move focus to any of the bound controls, but any other controls in the subform will be available.  To enable double clicking anywhere in the form put a giant button over the whole of the form, but not over any unbound controls you want to be available, and set its Transparent property to True (Yes).  Then put the code to open the other form in the button's DblClick event procedure.

    BTW, in answer to Imb's point, the Me keyword can be used in a subform's module.  It returns a reference to the current instance of the class in which the code is being executed, which in this case would be the current instance of the subform.

    Ken Sheridan, Stafford, England

    Thursday, August 10, 2017 12:21 PM
  • Thanks again guys! The project is coming along nicely. The major parts of it are completed. Currently working on export to excel and adding the different departments.
    Thursday, August 10, 2017 12:47 PM
  • BTW, in answer to Imb's point, the Me keyword can be used in a subform's module.  It returns a reference to the current instance of the class in which the code is being executed, which in this case would be the current instance of the subform.

    Hi,

    My reason for not using the Me keyword, is that I want to address many subforms at the same time both for reading and writing data. "Me" is only limited to that one subform, and therefore hard to automate.

    As an example I show my subform in design mode:

    and the one of the results of 2 main forms stacked:

    Imb.

    Thursday, August 10, 2017 1:19 PM
  • Oh! How do you change the background color like that?
    Thursday, August 10, 2017 1:55 PM
  • Oh! How do you change the background color like that?

    Hi Jamie,

    You can set the Backcolor property of a control the subform.

    In the above example the colors are ordered by colorname. It is one-click-on-a-button to make any other ordening.

    Imb.

    Thursday, August 10, 2017 2:39 PM
  • Can I make it so users can change the color of individual subforms? i.e. if a person is a contract vs military are they able to set different colors or army vs navt so on and so forth?
    Thursday, August 10, 2017 5:52 PM
  • Can I make it so users can change the color of individual subforms? i.e. if a person is a contract vs military are they able to set different colors or army vs navt so on and so forth?

    Hi Jaime,

    All of my applications (almost 100) have their own Backcolor. The example above has a blue color.

    When opening a main form with subforms, the subform inherates the backcolor of its Parent (thus the main form).

    In your case you want a Backcolor dependant on the Person (or Person_id). In that case you can change the Backcolor afterwards, by setting the Backcolor property of then subform:

            subform_ctl.Form.Detail.Backcolor = ....

    If your subform also has a header and/or footer, then these must be set too:

            subform_ctl.Form.FormHeader.Backcolor = ....
            subform_ctl.Form.FormFooter.Backcolor = ....

    Imb.

    Thursday, August 10, 2017 8:44 PM
  • "subform_ctl" refers to the individual name of my subforms? Remember I have 67 subform objects to display 67 different records at once on frmMain_3C. I'm trying to make the background of that individual record (subform object) to change colors depending on an individual field of the query attached to that record. For example in my first record's subform "sub01" I display the contact information of my first employee and I loop that record on my main form with the query ID field value of "1." There is another field in that query called "Branch." I want the background of each subform object to change to either blue when current record is identified as "USN" or green when current record is identified as "USA."

    here's the code I wrote on the subform's "onload" event, but its not working:

    Private Sub Form_Load()
    Set rs = CurrentDb.OpenRecordset("SELECT * FROM qryContacts_3C")
    
    If RecordSource = "SELECT * FROM qryContacts_3C WHERE qryContacts_3C.Branch='USN'" Then
    Me!Detail.BackColor = 8388608
    
    ElseIf RecordSource = "SELECT * FROM qryContacts_3C WHERE qryContacts_3C.Branch='USA'" Then
    Me!Detail.BackColor = 3329330
    
    Else
    Exit Sub
    
    End If
    End Sub
    
    
    


    Friday, August 11, 2017 11:07 AM