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

How do I determine row position for record 'nn' on continuous form 1

Status
Not open for further replies.

Trevil

Programmer
Jun 19, 2003
459
US
Access 2000

I need to be able to determine which visible detail row a user clicks on -- regardless of the record number. I have a continuous form that will show 13 rows in the detail section at one time. If I scroll down so that record number 30 is the first detail row shown, how can I get my grubby hands on the fact it is actually row 1?

Background:
If user double-clicks on a certain field in any row, I open a very small pop-up modal form that has only a combo box control, and that form gets positioned directly over the correct row and field. Works great for the first 13 records, but when I scroll down so that record 30 is the first visible row on the form, my pop-up position is wrong.

Main form has the following code in the double-click event:
iTop = (Me.CurrentRecord * Me.Detail.Height)
DoCmd.OpenForm "frmComboBox", acNormal, , , , , iTop

Pop-Up form has the following code in the load event:
DoCmd.MoveSize 1500, iTop

Thank You!
Wayne
 
Welcome to Tek-Tips. I invite you to read FAQ181-2886 to understand the how the site works, and how to get the most out of your Tek-Tips experience.

This is not as straightforward as any of us would like. You need a couple of APIs (GetCursorPos and ScreenToClient), the height in pixels of the detail row, the height of the subform header section if you have one, and need to account for if clicking on the last visible row actually scrolls the detail section by one row. I use the following code, and is triggered when the user selects a specific combobox field in the detail section. Also, this subform does not have a header section. I moved the header stuff from the subform to the mainform, so I wouldn't have to deal with it here.
Code:
Public Type POINTAPI
   tLng_Xloc               As Long
   tLng_YLoc               As Long
End Type

Public Declare Function GetCursorPos Lib "User32" (lpPoint As POINTAPI) As Long
Public Declare Function ScreenToClient Lib "User32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long

[COLOR=green]'Now inside the event handler for the combobox selection.[/color]

Private Sub cboField2_Enter()

   Dim lPnt_CursorPos   As POINTAPI
   Dim lLng_SubFrmTop   As Long
   Dim lInt_SelectRow   As Integer
   Dim lInt_CntlHght    As Integer

   GetCursorPos lPnt_CursorPos
   ScreenToClient Me.hWnd, lPnt_CursorPos
   lInt_CntlHght = Screen.ActiveControl.Height / 15
   lInt_SelectRow = Int(lPnt_CursorPos.tLng_YLoc / lInt_CntlHght) + 1
   lInt_SelectRow = IIf((lInt_SelectRow > 4), 4, lInt_SelectRow)

[COLOR=green]'lInt_SelectRow contains the actual visible row number that was clicked in.  Note that in this example, there are actually five visible rows, but clicking on the fifth row automatically scrolls that row into the 4th position[/color]

   lLng_SubFrmTop = [Forms]![frmIncsMaster]![subfrmIncList].Top
   lLng_SubFrmTop = lLng_SubFrmTop + ((lInt_SelectRow - 1) * Screen.ActiveControl.Height)

[COLOR=green]'Now lLng_SubFrmTop contains the Y position, in pixels, of the top of that detail row, relative to the mainform position.  This allows me to position (and make visible) a different subform at that specific location.[/color]

   OpenOtherSubForm lLng_SubFrmTop

End Sub
Remember, that my subform does not have a header section because, to be honest, I didn't want to have to mess with taking the header section height into account, in these calculations. Luckily, I didn't nead a header or footer in this case.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
First, Thank You for the speedy response.

I adjusted the code to account for my form header (I don't use a subform) and I'm getting the proper position - regardless of the record selected.

 
That's wonderful, and since you're able to modify the code, you must have a reasonable understanding of what's going on. That's great.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top