Once the user click on the record, my code finds out which record it is and transfer its data to certain fields.
So here is my code that I want to call when user clicks on record. It works great if the first clicked record is not the first one.
If it is the first one and my code got called then F.SelHeight = 0 and F.SelTop = 1.
But if I click the second one then F.SelHeight = 1 and F.SelTop = 2.
Then I go back and click the first one and F.SelHeight = 1 and F.SelTop = 1
Code:
Case "Contact_Address"
If DetailContact Then
Set F = Forms!DetailContact!ContactAssignedAddress.Form
Else
Set F = Forms!frmDatabaseDesktop!sfrmWorkspace.Form!ContactAssignedAddress.Form
End If
Set rs = F.RecordsetClone
If rs.RecordCount <> 0 Then
'Move to the first record in the recordset.
rs.MoveFirst
'Move to the first selected record.
rs.Move F.SelTop - 1
If F.SelHeight = 1 Then
Set rst = New ADODB.Recordset
Set cn = New ADODB.Connection
'Open connection to SQL Server
cn.Open strOLEDBConnect
cn.CursorLocation = adUseClient
rst.Open "SELECT * FROM dbo.Contact_Address WHERE ContAddressID = " & rs![ContAddressID], cn
If DetailContact Then
SetValuesContact_Address Forms!DetailContact, rst
Else
SetValuesContact_Address Forms!frmDatabaseDesktop!sfrmWorkspace.Form, rst
End If
ElseIf SelHeight > 1 Then
MsgBox "Can't edit more then one record at a time!"
End If
Set cn = Nothing
Set rst = Nothing
End If