Pass ID Of Row In Click Event (1 Viewer)

IgnoranceIsBliss

Registered User.
Local time
Yesterday, 23:10
Joined
Jun 13, 2019
Messages
35
@arnelgp in another thread of mine gave me a function that would open a form filtered to show only the specific ID information for the row I clicked on my form.

My database became corrupted and I had to re-create it and now it is not working. In the double click event of the field on my form I have the code
Code:
=OpenNotes("ID", [Comments])
And I have that method coded like this
Code:
Public Function OpenNotes(pkName As String, pkValue As Variant)
Dim strWhere As String
Select Case TypeName(pkValue)
Case "String" Then
    strWhere = pkName & " = '" & pkValue & "'"
Case "Integer", "Long", "Double", "Single"
    strWhere = pkName & " = " & pkValue
Case "Date"
    StrWhere = pkName & " = #" & Format(pkValue, "mm/dd/yyyy") & "#"
End Select
DoCmd.OpenForm FormName:="theFormToOpen", View:=acNormal, WhereCondition:=strWhere
End Function
Now when I step thro the code, if I hover over pkName, I see
Code:
pkName = "ID"
And
Code:
pkValue = the value of comments
HOWEVER it is comments for all records, not for the ID of the clicked row. What did I set-up incorrectly here in the redo?
 

theDBguy

I’m here to help
Local time
Yesterday, 23:10
Joined
Oct 29, 2018
Messages
10,099
Hi. What happens if you try it this way?
Code:
=OpentNotes("ID",[ID])
 

IgnoranceIsBliss

Registered User.
Local time
Yesterday, 23:10
Joined
Jun 13, 2019
Messages
35
Yes, that is it perfectly!! Thank you for the assistance.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 02:10
Joined
Feb 19, 2002
Messages
28,755
Naming all PK's "ID" isn't particularly user friendly.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom