Pass ID Of Row In Click Event (1 Viewer)

IgnoranceIsBliss

Registered User.
Local time
Today, 11:48
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
Staff member
Local time
Today, 11:48
Joined
Oct 29, 2018
Messages
21,358
Hi. What happens if you try it this way?
Code:
=OpentNotes("ID",[ID])
 

IgnoranceIsBliss

Registered User.
Local time
Today, 11:48
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, 14:48
Joined
Feb 19, 2002
Messages
42,971
Naming all PK's "ID" isn't particularly user friendly.
 

Users who are viewing this thread

Top Bottom