Results 1 to 4 of 4
  1. #1
    Lounger
    Join Date
    Jan 2001
    Location
    Rockville, MD USA
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Event When Record in Datasheet is Selected

    I want to be able to click on one control of four on a subform that is in datasheet view and have the data in that record/control be the basis of the criteria in a query.

    It was a while ago, but I seem to remember a post that explained how to have an action take place based on what I presented.

    Anyone?????

    Thank you

    Kirk Lavender

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Event When Record in Datasheet is Selected

    Referring to a control in the current record of a form is easy enough: put

    [Forms]![NameOfForm]![NameOfControl]

    in the criteria line under the appropriate field, with the actual name of the form and of the control substituted. Referring to the active control in a query is a lot more complicated. Perhaps someone can suggest a solution or workaround if you explain what you are trying to accomplish.

  3. #3
    Lounger
    Join Date
    Jan 2001
    Location
    Rockville, MD USA
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Event When Record in Datasheet is Selected

    I have a form that displays a maintenance procedure title, number, system... etc.

    On that form are subforms I have placed and required them to be viewed as datasheets. These subforms display the maintenance procedure

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Event When Record in Datasheet is Selected

    Create a query without criteria.
    Create a form based on the query, let's say you name it frmQuery.
    Create an On Dbl Click event procedure for the bound controls in the subform. For a control bound to a number field it would look like this:

    Private Sub Quantity_DblClick(Cancel As Integer)
    DoCmd.Openform FormName:="frmQuery", _
    WhereCondition:="[" & Me.ActiveControl.ControlSource & "] = " & Me.ActiveControl.Value
    End Sub

    For a text field, you need quotes around the value:

    Private Sub ItemName_DblClick(Cancel As Integer)
    DoCmd.Openform FormName:="frmQuery", _
    WhereCondition:="[" & Me.ActiveControl.ControlSource & "] = " & Chr(34) & Me.ActiveControl.Value & Chr(34)
    End Sub

    And for a date field, you need # around the value:

    Private Sub OrderDate_DblClick(Cancel As Integer)
    DoCmd.Openform FormName:="frmQuery", _
    WhereCondition:="[" & Me.ActiveControl.ControlSource & "] = #" & Format(Me.ActiveControl.Value, "mm/dd/yyyy") & "#"
    End Sub

    You could generalize this by supplying the data type as a parameter, or letting the code figure it out. This would enable you to put the event handler in a function that can be called from all controls.

Posting Permissions

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