INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Creating a calculated field in a query for record numbers.

Creating a calculated field in a query for record numbers.

(OP)
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?

RE: Creating a calculated field in a query for record numbers.

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]

RE: Creating a calculated field in a query for record numbers.

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close