Hi there,
Here is some code that I wrote...
In Access 2000 and above, you will need to add a reference to DAO (this reference is set by default in Acc 97, but in Acc 2000 and above, ADO is the default):
STEP 1: Set DAO Reference:
------------------
1. Within Access, press Alt+F11, to get to the 'code' environment
2. goto the menubar and select Tools|References...
3. here you will see a long list of 'available references'
4. If not already ticked, you will need to look through this list and find an item called "Microsoft DAO 3.6 Object Library". Tick this reference and press OK. (NOTE: the number "3.6" could be "3.51" or similar)
5. Done
STEP 2: Paste this Code into new Module:
----------------------------------------
1. Goto the menubar again and select Insert|Module
2. paste the following code into the module:
Public Function IsCurrentRecord(RowID As String, RowValue As Variant, f As Form) As Boolean
Dim rs As DAO.Recordset
Dim strCriteria As String
Dim lngCurrentRow As Long
On Error GoTo errHandler
IsCurrentRecord = False 'default
'create search criteria
If IsNumeric(RowValue) Then
strCriteria = "[" & RowID & "] = " & RowValue
Else
strCriteria = "[" & RowID & "] = '" & RowValue & "'"
End If
'find position of RowValue in recordset
Set rs = f.RecordsetClone
lngCurrentRow = f.CurrentRecord
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst
rs.FindFirst strCriteria
IsCurrentRecord = (rs.AbsolutePosition + 1 = lngCurrentRow)
End If
CleanUp:
exit function
errHandler:
Debug.print err.number & ": " & err.description
resume cleanup
End Function
STEP 3: Make Continuous Form
----------------------------
1. Create an invisible textbox within your continuous form
2. Name the textbox txtIsCurrentRecord
3. Set its control source to: =IsCurrentRecord("UniqueID",[UniqueID],[Form])
4. Replace the word "UniqueID" with the name of the field that can uniquely identify a record
e.g. If your form is based on a table like this:
myID LastName FirstName
1 Smith John
2 Jo Blogg
3 Jo Smith
then, the control source of the invisible textbox (txtIsCurrentRecord) would be:
=IsCurrentRecord("myID",[myID],[Form])
STEP 4: Add Conditional Formatting
----------------------------------
1. For each textbox that you wish to change the background colour, do the following
2. Goto the 'conditional formatting' form, and make 'condition 1' equal to:
Select "Expression Is"
In the expression box type: [txtIsCurrentRecord]=True
All done.
I hope this helps. Let me know if my instructions are hard to follow or i've made a mistake somewhere..
Cheers,
Dan