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

Creating a calculated field in a query for record numbers.

Status
Not open for further replies.

weightinwildcat

Programmer
May 11, 2010
84
0
0
US
I have a query with two tables that are connected through a left join. The query provides data to a sub-form. The main form show information about an order, and the sub-form show the line items for the order. I am looking for a way to add a calculated field that would show the record number for records generated by the query. If the number of a record matched the absolute position I am on in my record set, or the number of the form's current record minus one, I could use conditional formatting to highlight the record I am on. Any thoughts on how to do this?
 
To add a "record number" you can do a SQL Ranking query. But if you want to highlight the current record that can be done very easily.
1. Add a hidden textbox on the form called "txtBxSelected"
2. On the forms current event do
me.txtbxselected = me.nameOfPrimaryKey
3. In conditional formatting
expression is: [txtBxSelected] = [nameOfPrimaryKey]
 
That was the clue I needed. In case anybody else needs to know about this, here is the code I used:

Private Sub UpButton_Click()
Dim frm As Access.Form
Dim rs As Recordset

Set frm = Me.Parent.[Ship Partial Subform Two].Form
Set rs = frm.Recordset

If rs.AbsolutePosition = 0 Then
MsgBox "First Record"
Else
rs.MovePrevious
End If

Me.QtyToShipBox.value = ""
Me.NotesTextbox.value = ""
End Sub

Private Sub DownButton_Click()
Dim frm As Access.Form
Dim rs As Recordset

Set frm = Me.Parent.[Ship Partial Subform Two].Form
Set rs = frm.Recordset

If rs.AbsolutePosition = rs.RecordCount - 1 Then
MsgBox "Last Record"
Else
rs.MoveNext
End If

Me.QtyToShipBox.value = ""
Me.NotesTextbox.value = ""
End Sub

Private Sub Detail_Paint()
If Me.TextboxSelected.value = Me.OrderID_Textbox.value Then
Me.Detail.BackColor = RGB(255, 194, 14)
Me.Detail.AlternateBackColor = RGB(255, 194, 14)
Else
Me.Detail.BackColor = RGB(253, 253, 225)
Me.Detail.AlternateBackColor = RGB(229, 236, 245)
End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top