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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Continuous Forms 1

Status
Not open for further replies.

gavjb

Technical User
Jul 5, 2005
67
GB
Hi,

Does anyone know if it is possible to detect when a user selects a record (clicks the detail area for a particular form) on a continous form and if possible update a hidden value or even better change just the colour of the detail for that particular record and then again when you exit reset it back to normal.

I think it will most likly need some sort of custom control (if even then it is possible)

I need to do this as I need a way for the Parent form to know what record is selected when the user selects various options on the parent (I also want this visible to the user without show the awful record selector) .

The Alternative I am looking at is a tick box the user selects for the Record they want, but from what I remember as I want only one entry ticked at a time, to be able to do this I would need to update all the other record entries to false and then I would need to requery the form to update the display. The problem with this will be that if I have a lot of records the view will go back to the top of the form.

Thanks,


Gavin,
 
make an unbound textbox and hide it.
call it txtBxSelected
make this its control source:

=fncIsCurrent

Code:
Public Function fncIsCurrent(theID As Integer) As Boolean
  Dim rs As DAO.Recordset
  Set rs = Me.RecordsetClone
  rs.FindFirst ("autoID = " & theID) 'modify four your ID          
                                     'name
  If rs.AbsolutePosition + 1 = Me.currentRecord Then
    fncIsCurrent = True
  End If
End Function

Private Sub Form_Current()
 Me.Refresh
End Sub

Do conditional formatting on all controls

expression id [txtBxSelected] = true
 
the bottom line should read
expression is : [txtBxSelected] = true

There is probably an easier way but this worked. Also ensure that your recordset is sorted.
 
oops. Controls source should read
=fncIsCurrent([autoID])

where autoID is the name of my PK
 
Thanks, I had forgotten about expression id in conditional formatting.

I found a simpler way of getting the value on the form though (avoided any db coding)

Code:
Private iScheduleID As Integer

Private Sub Detail_Click()
    iScheduleID = Me.ScheduleID
    Me.Recalc
End Sub

Private Function GetMySchedule() As Integer

    GetMySchedule = iScheduleID

End Function

Private Sub Form_Open(Cancel As Integer)
    iScheduleID = Me.ScheduleID
    Me.Recalc
End Sub
 
Yeah I figured there was a simpler way. I Took some of your idea:

Code:
dim theID as integer

Public Function fncIsCurrent() As Boolean
  fncIsCurrent = (theID = Me.autoID)
End Function

Private Sub Form_Current()
 theID = Me.autoID
 Me.Recalc
End Sub

Private Sub Form_Load()
 theID = Me.autoID
End Sub

txtBxCurrent
= fncIsCurrent

Already have plans to use it. Thanks for the idea.
 
modified it to handle a new record

Dim theID As Variant

Public Function fncIsCurrent() As Boolean
fncIsCurrent = (Nz(theID, "New") = Nz(Me.autoID, "New"))
End Function
 
I use this Code in the OnCurrent event to change the Back colour of Combo Boxes and Text Boxes in continious forms



To use the code just
1) For the All text boxes and Comboboxes in your form set the tag porperty to CF
2) Have the Primary key as a Hidden text box
3) change YourID in the code below to the name of your primary key

'=======

Private Sub Form_Current()
Dim ctl As Control, strForm As String
Dim CurrentRecord As Variant
On Error Resume Next

'change YourID here to your primary key

CurrentRecord = Me!YourID
For Each ctl In Me.Controls
With ctl
If .Tag = "CF" Then
With Me.Controls(ctl.Name).FormatConditions _
.Delete
End With
'change YourID here to your primary key
With Me.Controls(ctl.Name).FormatConditions _
.Add(acExpression, , "[YourID]=" & CurrentRecord)
.BackColor = 16643528

End With
End If
End With
Next ctl
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top