Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlighting Records in Datasheet and base code on that

Status
Not open for further replies.

zevw

MIS
Jul 3, 2001
697
US
Is there a way that when I highlight a record in datasheet view to set a field to true and run code on the field that are set to true.

What happens now is, when I drag the mouse to 5 records my On Current Event only sets the first record that was highlighted to True all the others are not.

Code:
Private Sub Form_Current()

    If Nz(Me.Active, False) = False Then
        Me.Active = True
    Else
        Me.Active = False
    End If
    
    
End Sub

what can I do to detect which records are highlighted and set the field of those records to TRUE.
 
Thanks!

It works nicely when I highlighted some fields and ran the function manually it populated the fields and set the ACTIVE field to TRUE.

When should I call this function?

It seems that if I put it the Call in On Current Event Procedure like this

Code:
Private Sub Form_Current()

    Call DisplaySelectedCompanyNames
    
End Sub

it does not see anything selected yet. How can I start the procedure once I seleted all records I want Highlighted. Basicly after the last record was highlighted.
 
Easiest idea is to put a button in and call your function on click. To do this create a large blank form and drag your datasheet onto it. This makes it a subform within your new form but at least you can then place your button on the main form next to or under your data grid.

JB
 
I knew of this option but would rather automate it. Because I want to do the the same thing as in Excel to be able to select (highlight) rows (records) in different areas in the table and that should be done at once. That means every time a chunk or single row is selected, it should run the function.
 
I would look at the mouse up events, key up events of the form and the fields, then check for a selection.
 
How are ya zevw . . .

Try this is the forms [blue]Mouse Up[/blue] event:
Code:
[blue]   Dim x As Long, RST As DAO.Recordset
   
   If Me.SelHeight > 1 Then
      Set RST = Me.RecordsetClone
      
      RST.Move Me.SelTop - 1
      
      For x = 1 To Me.SelHeight
        Me.Active = True
        RST.MoveNext
      Next
      
      Set RST = nothing
   End If[/blue]
[blue]Your Thoughts . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top